Re: Return serial from insert

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Rory Campbell-Lange <mail(at)campbell-lange(dot)net>
Cc: Rod Kreisler <rod(at)23net(dot)net>, pgsql-novice(at)postgresql(dot)org
Subject: Re: Return serial from insert
Date: 2002-11-15 17:22:23
Message-ID: 20021115172223.GA3260@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Fri, Nov 08, 2002 at 16:02:07 +0000,
Rory Campbell-Lange <mail(at)campbell-lange(dot)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.

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Bruno Wolff III 2002-11-15 17:29:03 Re: Efficiency of stored procedure vs large join
Previous Message Tom Lane 2002-11-15 15:38:28 Re: core dump in psql (Is it a bug?)