Re: Last inserted id

Поиск
Список
Период
Сортировка
От Dave Page
Тема Re: Last inserted id
Дата
Msg-id AA30E7BCCA5C1D4E88A231900F8325C00C7A@dogbert.vale-housing.co.uk
обсуждение исходный текст
Ответ на Last inserted id  ("Simeo Reig" <simreig@terra.es>)
Список pgsql-odbc

> -----Original Message-----
> From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
> Sent: 12 November 2001 15:30
> To: Dhorwitz@ched.uct.ac.za
> Cc: 'pgsql-odbc@postgresql.org'
> Subject: Re: [ODBC] Last inserted id
>
>
> David Horwitz <Dhorwitz@ched.uct.ac.za> writes:
> > Actually the issue is b) is multi-user safe
> > *if*  you have an exclusive lock on the table. If you don't it is
> > quite possible for a user to insert an other record between your
> > insertion and the
> > currval() call
>
> False.  Option B is multi-user safe, period.  The reason is
> that currval returns the value last obtained by nextval *in
> your own session*, independently of what anyone else has done
> meanwhile.
>
> I tend to prefer option A (select nextval and insert) myself,
> just because it seems more intuitive.  But if that's not
> convenient for some reason, option B works fine too.

Ahh, now I see where the (== my) confusion has occurred. Option B) being:

- do insert
- select current val.

Whereas I originally was arguing against my interpretation of the question
which was:

- Select current val
- Do insert
- Select setval('seq', current_val + 1)

Which isn't safe.

Oh well.
My bad.

Regards, Dave.

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Last inserted id
Следующее
От: "Simeo Reig"
Дата:
Сообщение: Re: Last inserted id