Re: [GENERAL] get the previous assigned sequence value - Mailing list pgsql-general

From Ed Loehr
Subject Re: [GENERAL] get the previous assigned sequence value
Date
Msg-id 384F2CE4.115503C@austin.rr.com
Whole thread Raw
In response to get the previous assigned sequence value  (Kevin Heflin <kheflin@shreve.net>)
List 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



pgsql-general by date:

Previous
From: Thomas Drillich
Date:
Subject: pg_typemgr ;-) [was Re: [GENERAL] no primary key on self designed type]
Next
From: Bruce Momjian
Date:
Subject: Re: pg_typemgr ;-) [was Re: [GENERAL] no primary key on self designed type]