Re: Return serial from insert - Mailing list pgsql-novice

From Bruno Wolff III
Subject Re: Return serial from insert
Date
Msg-id 20021115172223.GA3260@wolff.to
Whole thread Raw
In response to Re: Return serial from insert  (Rory Campbell-Lange <mail@campbell-lange.net>)
List pgsql-novice
On Fri, Nov 08, 2002 at 16:02:07 +0000,
  Rory Campbell-Lange <mail@campbell-lange.net> wrote:
> The problem is that I need to use the id for naming an image file.
> Consequently I need the id from the insert. You will note (from my
> original messgage) that I'm already using a SERIAL type field for the id
> column.

Then you can select currval of the associated sequence.
currval returns the last value of the sequence assigned by this backend.
So as long as it is the same connection that did the insert and nothing
else using this connection has modified the sequence since the insert,
this will work.

pgsql-novice by date:

Previous
From: Tom Lane
Date:
Subject: Re: core dump in psql (Is it a bug?)
Next
From: Bruno Wolff III
Date:
Subject: Re: Efficiency of stored procedure vs large join