Select nextval problem

From: MT <mt(at)open2web(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Select nextval problem
Date: 2002-11-22 18:46:27
Message-ID: 3DDE7B83.4030105@open2web.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Earlier it was suggested I do this:

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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2002-11-22 18:56:43 Re: Lack of use of indexes
Previous Message Neil Conway 2002-11-22 18:26:35 Re: caveats upgrading from 7.0.3 to 7.2.x