Re: Select nextval problem - Mailing list pgsql-general

From Ron St.Pierre
Subject Re: Select nextval problem
Date
Msg-id 8G7F9.61884$ea.1090269@news2.calgary.shaw.ca
Whole thread Raw
In response to Re: Select nextval problem  (SZUCS Gábor <surrano@mailbox.hu>)
List pgsql-general
I use something similar (watch where nextval/currval are used):

         SELECT nextval('prodid_seq');

         INSERT INTO product VALUES (currval('prodid_seq'),'...',...,'');

         SELECT * FROM product WHERE prodid = (SELECT
nextval('prodid_seq'));



But there's probably a better way....


SZUCS Gábor wrote:

>>SELECT nextval('prodid_seq') as id;
>>
>>INSERT INTO product VALUES (nextval('prodid_seq'),'...',...,'');
>>
>>OK up to this point.
>>
>>Now how do I SELECT back the record I just inserted.
>>
>>SELECT * FROM product WHERE prodid = id;
>>ERROR:  Attribute 'id' not found
>>
>>OK, I'm not very good at SQL yet. How do you put the sequence number in
>>a place holder, then do the insert, and finally retrieve the record you
>>just inserted by matching the prodid with the number in the place holder.
>>
>>
>
>
>


--
Ron St.Pierre
Syscor R&D
tel: 250-361-1681
email: rstpierre@syscor.com


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: FATAL 1: Memory exhausted in AllocSetAlloc()
Next
From: Stephan Szabo
Date:
Subject: Re: Delete Order When Referential Integrity Is Active