Re: automatic sequence number?

From: Alessandro Polverini <polverini(at)nibbles(dot)it>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: automatic sequence number?
Date: 2003-11-04 17:25:07
Message-ID: 1067966707.5020.275.camel@japot.dyndns.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On Sun, 2003-11-02 at 15:28, apnv3(at)muha(dot)net wrote:
> Hello.
>
> I have a table with one field acting as primary key, the key is
> retrieved from a sequence-generator in postgresql.
> Currently I am executing two queries for every insert;
>
> Query #1 retrieves a number from a sequence-generator, and places it into the
> record.
>
> Query #2 performs the actual insert.
>
> Does anyone have an idea how to cut this down to only one query?
> And maybe somehow get back the primary key in the ResultSet.
>
> Or maybe this is how it is supposed to be done, it is just that I am not
> very experienced in jdbc/sql to know. :)

JDBC has native support for that with the method
Statement.getGeneratedKeys(), only I'm unsure postgresql jdbc driver
implements it (actually, querying DataBaseMetaData it says no).

I've asked the list some time ago for that information but I got no
response :(

Bye,
Alex

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Dave Cramer 2003-11-04 18:05:22 Re: automatic sequence number?
Previous Message Paul Thomas 2003-11-04 17:14:35 Re: too many clients