考慮一個 SQL 語句:select * from table where status in <statuses>其中 status 是枚舉:CREATE TYPE statusType AS ENUM ( 'enum1', 'enum2';在 Java 中,我有一個字符串表示形式的枚舉列表:List<String> list = new ArrayList<>();list.add("enum1");list.add("enum2");然后,我嘗試使用 SqlStatement 構建并執行查詢:handle.createQuery("select * from table where status in <statuses>") .bindList("statuses", statuses) .map(Mapper.instance) .list());我不斷收到以下錯誤:org.jdbi.v3.core.statement.UnableToExecuteStatementException: org.postgresql.util.PSQLException: ERROR: operator does not exist: status = character varying Hint: No operator matches the given name and argument types. You might need to add explicit type casts.我嘗試用 CAST(enum1 as statusType) 或 enum1::statusType 包裝每個列表項,但沒有成功。任何幫助表示贊賞。
1 回答

拉莫斯之舞
TA貢獻1820條經驗 獲得超10個贊
您可以將枚舉轉換為文本
handle.createQuery("select * from table where status::text in <statuses>")
.bindList("statuses", statuses)
.map(Mapper.instance)
.list());
添加回答
舉報
0/150
提交
取消