pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
selecting using array as IN condition parameter - possible?
2+ messages / 1 participants
[nested] [flat]

* selecting using array as IN condition parameter - possible?
@ 2010-09-29 12:59 John Lister <john.lister@kickstone.com>
  0 siblings, 0 replies; 2+ messages in thread

From: John Lister @ 2010-09-29 12:59 UTC (permalink / raw)
  To: pgsql-jdbc

Hi, suppose I have a query such as

select * from blah where (a,b) in ( (1,2),(2,3),(3,4)...) 

I'd like to do this using jdbc and use a list/array for the IN parameter.

using postgresql 8.3, it is possible to rewrite it so that I am passing in an array instead of a hardcoded list as so

select * from blah where (a, b)::myPairType = any ( array of myPairType) 

provided I've created a type (myPairType) to represent my data pair and a comparison operator for the new data type.

My question is therefore is it possible to pass an array of this type using jdbc or alternatively pass an array of arrays to represent my pair and convert that in the sql?

Thanks

John
--

Got needs? Get Goblin'! - http://www.pricegoblin.co.uk/

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: selecting using array as IN condition parameter - possible?
@ 2010-09-29 17:58 John Lister <john.lister@kickstone.com>
  0 siblings, 0 replies; 2+ messages in thread

From: John Lister @ 2010-09-29 17:58 UTC (permalink / raw)
  To: pgsql-jdbc

  Hi, after some more searching on the net I came across references to 
PGobject and got this working using standard JDBC calls which is a good 
start, I don't suppose any one has any hints about using this in JPA 
queries under eclipselink? I've created a converter for the single case, 
but i get errors when I try and use an array.

If I try and receive an array I get a not implemented error on 
getArrayImpl due to the use of a Map. Conversely if I construct an array 
of my PGobjects subclasses and try to pass that as a parameter to a 
query I get an exception that setObject can't infer the sql type needed 
and to provide an explicit one. I was hoping that as PGobject has a 
getType method that it would be used?

Is it possible to specify the type when passing an array using JPA?

Thanks

John


On 29/09/2010 13:59, John Lister wrote:
> Hi, suppose I have a query such as
> select * from blah where (a,b) in ( (1,2),(2,3),(3,4)...)
> I'd like to do this using jdbc and use a list/array for the IN parameter.
> using postgresql 8.3, it is possible to rewrite it so that I am 
> passing in an array instead of a hardcoded list as so
> select * from blah where (a, b)::myPairType = any ( array of myPairType)
> provided I've created a type (myPairType) to represent my data pair 
> and a comparison operator for the new data type.
> My question is therefore is it possible to pass an array of this type 
> using jdbc or alternatively pass an array of arrays to represent my 
> pair and convert that in the sql?
> Thanks
> John
> --
> Got needs? Get Goblin'! - http://www.pricegoblin.co.uk/

^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2010-09-29 17:58 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-09-29 12:59 selecting using array as IN condition parameter - possible? John Lister <john.lister@kickstone.com>
2010-09-29 17:58 Re: selecting using array as IN condition parameter - possible? John Lister <john.lister@kickstone.com>

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