我的问题与此类似
PostgreSQL check if array contains any element from left-hand array
但我想执行(上述问题中给出的相同查询),即"&&操作员"通过代码查询。 Dropwizard + JDBI框架。
@SqlQuery("SELECT ARRAY[1,2,3,4] && <input_array>")
public abstract Object query(@BindIn("input_array") List<Integer> list);
@BindIn注释不起作用。低于错误。
! org.postgresql.util.PSQLException: ERROR: operator does not exist:
integer[] && integer
! Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
! Position: 41
! at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2270)
! at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1998)
! at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
! at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:570)
! at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:420)
! at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:413)
! at org.skife.jdbi.v2.SQLStatement.internalExecute(SQLStatement.java:1327)
! ... 75 common frames omitted
! Causing: org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException: org.postgresql.util.PSQLException: ERROR: operator does not exist: integer[] && integer
! Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
! Position: 41 [statement:"SELECT ARRAY[1,2] && <input_array>", located:"SELECT ARRAY[1,2] && :__input_array_0,:__input_array_1", rewritten:"/* Monoliths.query */ SELECT ARRAY[1,2] && ?,?", arguments:{ positional:{}, named:{__input_array_1:3,__input_array_0:2}, finder:[]}]
! at org.skife.jdbi.v2.SQLStatement.internalExecute(SQLStatement.java:1338)
! at org.skife.jdbi.v2.Query.fold(Query.java:173)
! at org.skife.jdbi.v2.Query.first(Query.java:273)
! at org.skife.jdbi.v2.Query.first(Query.java:264)
! at org.skife.jdbi.v2.sqlobject.ResultReturnThing$SingleValueResultReturnThing.result(ResultReturnThing.java:110)
! at org.skife.jdbi.v2.sqlobject.ResultReturnThing.map(ResultReturnThing.java:46)
! at org.skife.jdbi.v2.sqlobject.QueryHandler.invoke(QueryHandler.java:41)
! at org.skife.jdbi.v2.sqlobject.SqlObject.invoke(SqlObject.java:224)
! at org.skife.jdbi.v2.sqlobject.SqlObject$3.intercept(SqlObject.java:133)
请指导我,我是Dropwizard-JDBI和PostgreSQL的新手。
Above method is called as
List<Integer> list = new ArrayList<>();
list.add(2);
list.add(3);
query(list);
Dropwizard版本 - 1.1.0
Java 8
答案 0 :(得分:0)
我认为您应该尝试这样的事情:
where date >= trunc(sysdate, 'mon') - interval '12' month and
date < trunc(sysdate, 'mon') - interval '11' month