亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何通過 postgresql 查詢在字符串列表中搜索枚舉?

如何通過 postgresql 查詢在字符串列表中搜索枚舉?

料青山看我應如是 2023-12-13 16:26:36
考慮一個 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());


查看完整回答
反對 回復 2023-12-13
  • 1 回答
  • 0 關注
  • 148 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號