Skip site navigation (1) Skip section navigation (2)

Re: Using SELECT IN with prepared statement

From: Ingmar Lötzsch <iloetzsch(at)asci-systemhaus(dot)de>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Using SELECT IN with prepared statement
Date: 2008-11-11 07:38:38
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-jdbc

you can use another syntax

WHERE userid = ANY (?)

and call PreparedStatement.setArray(). That means, you have to provide 
an instance of java.sql.Array as parameter. For this purpose you can 
implement this interface (It's not too difficult, I've done this.) or 
use Connection.createArrayOff(). The last is available dependent on the 
JDBC-Library you use. I have not tried it yet.

One advantage of ANY instead of IN is, that you can pass an empty array 
without causing a SQL syntax error.


Tiago Alves schrieb:
> Greetings!
> Sorry if you answer this before, I couldn't find it.
> I want to do something like:
> PreparedStatement ps = connection.prepareStatement("select * from users 
> where userid in ?");
> ps.setSomething(anIntArray);
> Is this possible? How?
> Thanks.
> Tiago A.

In response to


pgsql-jdbc by date

Next:From: Alexander PanzhinDate: 2008-11-11 10:19:40
Subject: Re: Using SELECT IN with prepared statement
Previous:From: Oliver JowettDate: 2008-11-11 01:46:04
Subject: Re: Pgsql jdbc driver 8.3 Build 603: Commit deadlock

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group