Message-ID: <3DDD9AFA.1010901@open2web.com>
Date: Thu, 21 Nov 2002 21:48:26 -0500
From: MT <mt@open2web.com>
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.1) Gecko/20020827
X-Accept-Language: en-us, sv
MIME-Version: 1.0
To: Ericson Smith <eric@did-it.com>
Subject: Re: [GENERAL] selecting the last record from a table
References: <3DDA88DF.2080105@open2web.com>
	<m38yzpl6nr.fsf@varsoon.wireboard.com>
	<1037734374.1500.1.camel@localhost.localdomain>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

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



