Re: Using SELECT IN with prepared statement

Поиск
Список
Период
Сортировка
От Ingmar Lötzsch
Тема Re: Using SELECT IN with prepared statement
Дата
Msg-id 4919A960.9050904@asci-systemhaus.de
обсуждение исходный текст
Ответ на Re: Using SELECT IN with prepared statement  (Alexander Panzhin <jalexoids@gmail.com>)
Ответы Re: Using SELECT IN with prepared statement  (Guillaume Cottenceau <gc@mnc.ch>)
Список pgsql-jdbc
Hello Alexander,

 > You need to write: select * from users where userid = ANY ?

I have not found another way to use an array. You can execute the
following statements:

SELECT 1 = ANY (ARRAY[1, 2]);
SELECT 1 = ANY ('{3, 2}');
SELECT 1 = ANY ('{}');
SELECT 1 IN (1, 2);

You can't execute

SELECT 1 IN (ARRAY[1, 2]);

because IN expects "a parenthesized list of scalar expressions".

See
http://www.postgresql.org/docs/8.3/interactive/functions-comparisons.html
too.

Of course you can concatenate the values like

String idlist = "1, 2";
String sql = "SELECT" + ... + "WHERE id IN (" + idlist + ")";

and execute the statement. But there is no parameter.

Ingmar

Alexander Panzhin schrieb:
> Hi,
>
> You need to write: select * from users where userid = ANY ?
>
> See
> http://www.postgresql.org/docs/8.3/interactive/functions-comparisons.html
>
> Tiago Alves wrote:
>> 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.
>>
>


В списке pgsql-jdbc по дате отправления:

Предыдущее
От: "Shawn Chasse"
Дата:
Сообщение: Re: Pgsql jdbc driver 8.3 Build 603: Commit deadlock
Следующее
От: Guillaume Cottenceau
Дата:
Сообщение: Re: Using SELECT IN with prepared statement