Re: Returning generated id after a transaction.

Поиск
Список
Период
Сортировка
От Bartosz Dmytrak
Тема Re: Returning generated id after a transaction.
Дата
Msg-id CAD8_UcaajQL217J3WgXx8L2TZwKVtQQ-HzU2YgLKxD3T8_GS_Q@mail.gmail.com
обсуждение исходный текст
Ответ на Returning generated id after a transaction.  (Guillaume Henriot <henriotg@gmail.com>)
Ответы Re: Returning generated id after a transaction.  (Guillaume Henriot <henriotg@gmail.com>)
Список pgsql-novice
Hi,
which postgres version You are using?
do You perform this in function or as anonymous block, or at hoc query?

regards,
Bartek


2012/4/18 Guillaume Henriot <henriotg@gmail.com>
Hi,

First of all excuse me if i'm not precise enough, english is not my native language.

I have a small problem while using transactions. I'm doing an INSERT in one table, an UPDATE in another table and then i'm trying to retrieve the id generated by the serial in the first table but the few things I have tryed does not return anything. Here is a sample of my transaction:

BEGIN;
INSERT INTO table1 (id, name) VALUES (DEFAULT, 'name_of_the_entry');
UPDATE table2 SET table1_id = CURRVAL('table1_id_seq') WHERE id = 'some_row_id';
SELECT CURRVAL('parts_id_seq') AS table1_id;
COMMIT;

I have tryed with RETURNING id on the INSERT too and pgadmin tells me each time this kind of message : "query result of 1 line cancelled".

It works well when I do it without the begin and commit, so as a pgsql beginner I'm a bit lost.


Guillaume Henriot

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

Предыдущее
От: Guillaume Henriot
Дата:
Сообщение: Returning generated id after a transaction.
Следующее
От: ennio
Дата:
Сообщение: Re: Escaping literal strings in pg_8.4