Re: return column id from insert - Mailing list pgsql-novice

From Oliver Elphick
Subject Re: return column id from insert
Date
Msg-id 1037111228.11992.817.camel@linda
Whole thread Raw
In response to return column id from insert  (Rory Campbell-Lange <mail@campbell-lange.net>)
List pgsql-novice
On Tue, 2002-11-12 at 11:50, Rory Campbell-Lange wrote:
> I asked a question about this earlier, and didn't get a response I
> understood!
>
> The issue is this:
> I need to make a database insert and then make an image with the
> resulting column id number, which is provided by a sequence.
>
> This has to be a single action, otherwise I could fall into a race
> condition with another insert going on concurrently.

Use the function currval('sequence_name') to get the last value
generated by that sequence in your current session.  You must have
previously called nextval('sequence_name') in the same session, either
explicitly or through an insert to a table with a SERIAL type field.

--
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight, UK
http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
                 ========================================
     "He that loveth father of mother more than me is not
      worthy of me; and he that loveth son or daughter more
      than me is not worthy of me. And he that taketh not
      his cross, and followeth after me, is not worthy of
      me."                   Matthew 10:37,38


pgsql-novice by date:

Previous
From: Rory Campbell-Lange
Date:
Subject: return column id from insert
Next
From: "Patrick Hatcher"
Date:
Subject: Re: Cancelling long running query?