pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Daron Ryan <daron.ryan@gmail.com>
To: Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: PreparedStatement for set membership (The IN operator)
Date: Tue, 05 Apr 2011 22:09:08 +0930
Message-ID: <4D9B0D6C.70707@gmail.com> (raw)
In-Reply-To: <4D9AD284.1090306@enterprisedb.com>
References: <4D9AC223.4000602@gmail.com>
	<4D9AD284.1090306@enterprisedb.com>

  Thanks Heikki. I have tried using the setArray method but I am still 
running into an error.

Exception in thread "main" org.postgresql.util.PSQLException: Unknown 
type _INTEGER.
         at 
org.postgresql.jdbc2.AbstractJdbc2Statement.setArray(AbstractJdbc2Statement.java:2800)
         at dictionary.test.Main.main(Main.java:85)

This is the Array implementation I have created.
http://pastebin.com/tkzPRL4A

For baseTypeName I have also tried "int" and received the same error 
referring to type _int instead.

This is the code I used to test the implementation
calling code
http://pastebin.com/T1mvADaF

Any idea what I need to do?


On 5/04/2011 5:57 PM, Heikki Linnakangas wrote:
> On 05.04.2011 10:17, Daron Ryan wrote:
>> Hello,
>>
>> I need to use a SELECT statement with varying data for set 
>> membership. IE.
>>
>> SELECT link_id
>> FROM links
>> WHERE heading_id IN (?, ?, ?)
>>
>> It won't always be the same number of members in the set. I am using an
>> ordinary statement with an executeQuery call but would prefer to use a
>> PreparedStatement. Is this possible? If so how do I set the values in
>> the set?
>
> You can do "WHERE heading_id = ANY (?)", and pass an array of the ids 
> for the parameter.
>




view thread (6+ messages)  latest in thread

Message-ID: <4D9B0D6C.70707@gmail.com>
Permalink:  ../4D9B0D6C.70707@gmail.com/
Also on:    postgresql.org/message-id/4D9B0D6C.70707@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: daron.ryan@gmail.com, heikki.linnakangas@enterprisedb.com
  Subject: Re: PreparedStatement for set membership (The IN operator)
  In-Reply-To: <4D9B0D6C.70707@gmail.com>
  References: <4D9AC223.4000602@gmail.com> <4D9AD284.1090306@enterprisedb.com> <4D9B0D6C.70707@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox