Re: Serial key - Mailing list pgsql-jdbc

From John Sidney-Woollett
Subject Re: Serial key
Date
Msg-id 3567.192.168.0.64.1076696509.squirrel@mercury.wardbrook.com
Whole thread Raw
In response to Re: Serial key  ("Chris Smith" <cdsmith@twu.net>)
Responses Re: Serial key  (Kris Jurka <books@ejurka.com>)
List 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

pgsql-jdbc by date:

Previous
From: Bhushan Bhangale
Date:
Subject: Re: Serial key
Next
From: Kris Jurka
Date:
Subject: Re: Startup message issues