Re: MySQL LAST_INSERT_ID() to Postgres

Поиск
Список
Период
Сортировка
От Scott Marlowe
Тема Re: MySQL LAST_INSERT_ID() to Postgres
Дата
Msg-id dcc563d10808281506t48260986i6339410a39b53142@mail.gmail.com
обсуждение исходный текст
Ответ на Re: MySQL LAST_INSERT_ID() to Postgres  (Bill <pg@dbginc.com>)
Ответы Re: MySQL LAST_INSERT_ID() to Postgres  (Joshua Drake <jd@commandprompt.com>)
Re: MySQL LAST_INSERT_ID() to Postgres  ("D. Dante Lorenso" <dante@lorenso.com>)
Re: MySQL LAST_INSERT_ID() to Postgres  (Bill <pg@dbginc.com>)
Список pgsql-general
On Thu, Aug 28, 2008 at 3:38 PM, Bill <pg@dbginc.com> wrote:
> I am new to PostgreSQL but it seems to me that lastval() will only work if
> the insert does not produce side effects that call nextval(). Consider the
> case where a row is inserted into a table that has an after insert trigger
> and the after insert trigger inserts a row into another table which has a
> serial primary key. In that case I assume that lastval() will  return the
> value from the serial column in the second table.

No, setval, currval, and lastval all require as an argument a sequence
name.  So the real issue is you have to know the sequence name to use
them.

The problem with lastval is that it reports the last value that the
sequence gave out whether it was to us or someone else.  this makes it
NOT SAFE for concurrent transactions, but more for maintenance work.

I use returning almost exclusively now.

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

Предыдущее
От: "Fernando Moreno"
Дата:
Сообщение: log_statement not working on pl/pgsql functions
Следующее
От: "Albretch Mueller"
Дата:
Сообщение: Re: ERROR: relation . . . does not exist