Subject: Re: [GENERAL] selecting the last record from a table
From: MT <[email-masked]>
To: Ericson Smith <[email-masked]>
Date: Thu, 21 Nov 2002 21:48:26 -0500

Ericson Smith wrote:
> You might want to get the sequence before you even do the insert...
> 
> SELECT nextval('my_sequence') as id
> 
> Then do the insert with the sequence and all other operations with the
> "id". Sure you might have a few holes in the sequence if you abort an
> insert, but this way you dont have to mess with OID's etc.

This looks like the best solution, my only problem is the SQL:

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.

Thanks for your help in this matter.

Mark