Re: last id

Поиск
Список
Период
Сортировка
От Josh Berkus
Тема Re: last id
Дата
Msg-id 200306262128.56135.josh@agliodbs.com
обсуждение исходный текст
Ответ на last id  ("Ramil G. Sagum" <ramil@astra.ph>)
Список pgsql-novice
Ramil,

> 1. insert a row to table A
> 2. get the value of the serial field from the now in no.1
> 3. insert a row to table B (one of the fields uses the value from no.2)
>
> in -one transaction-?

BEGIN TRANSACTION

INSERT INTO table_a ( 2, 3, 4 )
VALUES ( x, y, z );
INSERT INTO table_b ( a_FK, 3, 4 )
VALUES ( CURRVAL('table_a_seq'), m, q );

COMMIT TRANSACTION

Easy, neh?   Now go to the online docs and do some reading about Sequences.

--
Josh Berkus
Aglio Database Solutions
San Francisco

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

Предыдущее
От: "Ramil G. Sagum"
Дата:
Сообщение: last id
Следующее
От: "Giorgio Ponza"
Дата:
Сообщение: Probably a stupid question