Обсуждение: Using "where col in (?)"
I am getting the following JDBC error:
ERROR: operator does not exist: integer = integer[]
Hint: No operator matches the given name and argument types. You might
need to add explicit type casts. Position: 37
My query looks like this:
select * from se_user where user_id in (?)
I am using a prepared statement.
I am doing:
Integer [] ary = new Integer[]{ 3, 4, 5 };
pstmt.setArray(1, conn.createArrayOf("integer", ary));
I also tried:
Integer [] ary = new Integer[]{ 3, 4, 5 };
pstmt.setObject(1, conn.createArrayOf("integer", ary));
Neither worked. user_id is an integer column.
Sure appreciate some help.
Thanks!
Blake McBride
ERROR: operator does not exist: integer = integer[]
Hint: No operator matches the given name and argument types. You might
need to add explicit type casts. Position: 37
My query looks like this:
select * from se_user where user_id in (?)
I am using a prepared statement.
I am doing:
Integer [] ary = new Integer[]{ 3, 4, 5 };
pstmt.setArray(1, conn.createArrayOf("integer", ary));
I also tried:
Integer [] ary = new Integer[]{ 3, 4, 5 };
pstmt.setObject(1, conn.createArrayOf("integer", ary));
Neither worked. user_id is an integer column.
Sure appreciate some help.
Thanks!
Blake McBride
On Fri, 29 Apr 2022 at 11:25, Blake McBride <blake1024@gmail.com> wrote:
I am getting the following JDBC error:
ERROR: operator does not exist: integer = integer[]
Hint: No operator matches the given name and argument types. You might
need to add explicit type casts. Position: 37
My query looks like this:
select * from se_user where user_id in (?)
I am using a prepared statement.
I am doing:
Integer [] ary = new Integer[]{ 3, 4, 5 };
pstmt.setArray(1, conn.createArrayOf("integer", ary));
I also tried:
Integer [] ary = new Integer[]{ 3, 4, 5 };
pstmt.setObject(1, conn.createArrayOf("integer", ary));
Neither worked. user_id is an integer column.
Sure appreciate some help.
Any chance you can provide server logs for that. I'm curious what the server saw.
Dave
Thanks!
Blake McBride
On Fri, Apr 29, 2022 at 8:25 AM Blake McBride <blake1024@gmail.com> wrote:
I am getting the following JDBC error:
The error is a PostgreSQL one, JDBC is just the messenger here.
ERROR: operator does not exist: integer = integer[]
Hint: No operator matches the given name and argument types. You might
need to add explicit type casts. Position: 37
select * from se_user where user_id in (?)
Why are you expecting: "integer IN (integer[])" to work? It isn't documented anywhere that I'm aware of.
You can write that as: "integer = ANY(integer[])" though, that is documented.
David J.
On Fri, 29 Apr 2022 at 11:32, David G. Johnston <david.g.johnston@gmail.com> wrote:
On Fri, Apr 29, 2022 at 8:25 AM Blake McBride <blake1024@gmail.com> wrote:I am getting the following JDBC error:The error is a PostgreSQL one, JDBC is just the messenger here.
ERROR: operator does not exist: integer = integer[]
Hint: No operator matches the given name and argument types. You might
need to add explicit type casts. Position: 37
select * from se_user where user_id in (?)Why are you expecting: "integer IN (integer[])" to work? It isn't documented anywhere that I'm aware of.You can write that as: "integer = ANY(integer[])" though, that is documented.
Thanks David, good catch!
Dave
I am wanting it to do the same as: select * from se_user where user_id in (3, 4, 5)
On Fri, Apr 29, 2022 at 10:32 AM David G. Johnston <david.g.johnston@gmail.com> wrote:
On Fri, Apr 29, 2022 at 8:25 AM Blake McBride <blake1024@gmail.com> wrote:I am getting the following JDBC error:The error is a PostgreSQL one, JDBC is just the messenger here.
ERROR: operator does not exist: integer = integer[]
Hint: No operator matches the given name and argument types. You might
need to add explicit type casts. Position: 37
select * from se_user where user_id in (?)Why are you expecting: "integer IN (integer[])" to work? It isn't documented anywhere that I'm aware of.You can write that as: "integer = ANY(integer[])" though, that is documented.David J.
On Friday, April 29, 2022, Blake McBride <blake1024@gmail.com> wrote:
I am wanting it to do the same as: select * from se_user where user_id in (3, 4, 5)
Then rewrite the query to use the “val = any(array)” expression like I said.
David J.
That works. Thank you!!
On Fri, Apr 29, 2022 at 10:43 AM David G. Johnston <david.g.johnston@gmail.com> wrote:
On Friday, April 29, 2022, Blake McBride <blake1024@gmail.com> wrote:I am wanting it to do the same as: select * from se_user where user_id in (3, 4, 5)Then rewrite the query to use the “val = any(array)” expression like I said.David J.