Select nextval problem

Поиск
Список
Период
Сортировка
От MT
Тема Select nextval problem
Дата
Msg-id 3DDE7B83.4030105@open2web.com
обсуждение исходный текст
Список 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
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




В списке pgsql-general по дате отправления:

Предыдущее
От: Hans-Jürgen Schönig
Дата:
Сообщение: Using SHOW in PL/pgSQL
Следующее
От: dave_h4@yahoo.com (Hunter)
Дата:
Сообщение: escape single quote in INSERT command