Skip site navigation (1) Skip section navigation (2)

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: (view raw, whole thread or download thread mbox)
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


pgsql-jdbc by date

Next:From: Kris JurkaDate: 2004-02-13 18:33:24
Subject: Re: Startup message issues
Previous:From: Bhushan BhangaleDate: 2004-02-13 17:48:34
Subject: Re: Serial key

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group