Avoiding a race condition

Поиск
Список
Период
Сортировка
От MT
Тема Avoiding a race condition
Дата
Msg-id 3DDF9811.2060809@open2web.com
обсуждение исходный текст
Ответы Re: Avoiding a race condition  (Oliver Elphick <olly@lfix.co.uk>)
Список pgsql-general
Earlier I wrote a note asking how I could insert a record and then
display that record as verification that it had been successfully
inserted. I got several suggestions, the following which I'd like to use:

SELECT nextval('my_sequence') as id

Then do the insert with the sequence and all other operations with the
"id".

I've tried to do this without success. Could someone show me the syntax
since I can't figure it out.

I've tried:

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 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Hung Postgres Processes
Следующее
От: Oliver Elphick
Дата:
Сообщение: Re: Avoiding a race condition