Re: Subselect query for a multi table insert single query

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Subselect query for a multi table insert single query
Дата
Msg-id 9267.1032732205@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Subselect query for a multi table insert single query  ("Norman Khine" <norman@khine.net>)
Список pgsql-novice
"Norman Khine" <norman@khine.net> writes:
> 1) INSERT INTO business_name (business_name, business_url)
>   values ('<dtml-var business_name>', '<dtml-var business_url>');

> 2) select last_value from business_name_business_name_seq

Instead use

    select currval('business_name_business_name_seq');

to get the assigned sequence value without a race condition.  See
http://www.ca.postgresql.org/users-lounge/docs/7.2/postgres/functions-sequence.html

Actually you don't need to bother with the separate select, unless
your client code needs that ID for other purposes.  You could just
write the currval() call in the second INSERT.

            regards, tom lane

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

Предыдущее
От: "Norman Khine"
Дата:
Сообщение: Subselect query for a multi table insert single query
Следующее
От: "Thomas_Fahey"
Дата:
Сообщение: writing to external file