Re: Serial key

From: "John Sidney-Woollett" <johnsw(at)wardbrook(dot)com>
To: "Chris Smith" <cdsmith(at)twu(dot)net>
Cc: "Bhushan Bhangale" <bbhangale(at)lastminute(dot)com>, pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Serial key
Date: 2004-02-13 18:21:49
Message-ID: 3567.192.168.0.64.1076696509.squirrel@mercury.wardbrook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Chris Smith said:
The only other approach is to
> use
> some unique set of columns in the table other than your numeric key, and
> immediately follow your insert statement with a select. This only works
> if
> your records are unique without regard to the generated key. As an
> example,
> you'd do:
>
> insert into mytable (name, department, position, hiredate)
> values('jdoe', 'eng', 'manager', DATE '10-12-1994');
>
> select empid from mytable where
> name = 'jdoe' AND
> department = 'eng' AND
> position = 'manager' AND
> hiredate = DATE '10-12-1994';
>

Alternatively, if you could use a sequence object for the primary key
value (instead of a serial column), and you switched autocommit off, you
should be able to determine the last allocated PK id AFTER creating the
record by querying the currval on the sequence.

John Sidney-Woollett

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Kris Jurka 2004-02-13 18:33:24 Re: Startup message issues
Previous Message Bhushan Bhangale 2004-02-13 17:48:34 Re: Serial key