Re: [GENERAL] get the previous assigned sequence value
Ed Loehr <eloehr@austin.rr.com>
From: Ed Loehr <ELOEHR@austin.rr.com>
To: Kevin Heflin <kheflin@shreve.net>
Cc: "PGSQL-General (E-mail)" <pgsql-general@postgresql.org>
Date: 1999-12-09T04:15:32Z
Lists: pgsql-general
Kevin Heflin wrote:
> I've been looking through the online docs, so far have not found this
> information.
>
> After an INSERT, I want to retrieve the value of the sequence I use for
> unique_ids
>
> Any suggestions ?
Use the OID returned from the INSERT to select the newly created value,
i.e.,
insert into mytable (stuff...) ...
select id from mytable where oid = NNNN...
How to get the OID in the first example varies depending on your interface
(perl/DBI, PL/pgsql, etc).
Alternatively, use the currval(mytable_id_seq) function within the same
session immediately after the insert.
Cheers.
Ed