pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Correct way to send a composite type to Postgres
3+ messages / 2 participants
[nested] [flat]

* Correct way to send a composite type to Postgres
@ 2010-02-16 11:13  Jason Tesser <jasontesser@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Jason Tesser @ 2010-02-16 11:13 UTC (permalink / raw)
  To: pgsql-jdbc

I have a composite type that is an IN parameter for a Stored Function.  How
do I construct the type in Java?

I know in Postgres I can do row(...)  I was hoping for something a little
more Javaish instead to having to build that String.

Can I extend PGObject to accomplish this?

Thanks,
Jason Tesser
dotCMS Lead Development Manager
1-305-858-1422

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

* Re: Correct way to send a composite type to Postgres
@ 2010-02-18 05:17  Kris Jurka <books@ejurka.com>
  parent: Jason Tesser <jasontesser@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Kris Jurka @ 2010-02-18 05:17 UTC (permalink / raw)
  To: Jason Tesser <jasontesser@gmail.com>; +Cc: pgsql-jdbc



On Tue, 16 Feb 2010, Jason Tesser wrote:

> I have a composite type that is an IN parameter for a Stored Function.  How
> do I construct the type in Java?
> 
> I know in Postgres I can do row(....)  I was hoping for something a little
> more Javaish instead to having to build that String.
> 
> Can I extend PGObject to accomplish this?

Currently there isn't a great way to do this with the PG JDBC driver.  You 
can encapsulate the ugliness with PGObject, but you can't avoid it.  If 
you have a type that extends PGObject all you need to do is override the 
toString method to format the data as the server expects it.

Kris Jurka


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

* Re: Correct way to send a composite type to Postgres
@ 2010-02-18 11:48  Jason Tesser <jasontesser@gmail.com>
  parent: Kris Jurka <books@ejurka.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Jason Tesser @ 2010-02-18 11:48 UTC (permalink / raw)
  To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc

yea that is what i did.  I was wondering though if there are gotchas here
for escaping?  Are here are Utilities in the driver I can use to make sure
the data is escaped ok?  any thoughts here.

I mean basically i did

public String getValue() {
        return "(" + person.getId() + "," + person.getFirstName() + "," +
person.getLastName() + "," + person.getMiddleName() + ")";
}


On Thu, Feb 18, 2010 at 12:17 AM, Kris Jurka <books@ejurka.com> wrote:

>
>
> On Tue, 16 Feb 2010, Jason Tesser wrote:
>
>  I have a composite type that is an IN parameter for a Stored Function.
>> How
>> do I construct the type in Java?
>>
>> I know in Postgres I can do row(....)  I was hoping for something a little
>> more Javaish instead to having to build that String.
>>
>> Can I extend PGObject to accomplish this?
>>
>
> Currently there isn't a great way to do this with the PG JDBC driver.  You
> can encapsulate the ugliness with PGObject, but you can't avoid it.  If you
> have a type that extends PGObject all you need to do is override the
> toString method to format the data as the server expects it.
>
> Kris Jurka

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


end of thread, other threads:[~2010-02-18 11:48 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-02-16 11:13 Correct way to send a composite type to Postgres Jason Tesser <jasontesser@gmail.com>
2010-02-18 05:17 ` Kris Jurka <books@ejurka.com>
2010-02-18 11:48   ` Jason Tesser <jasontesser@gmail.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