Re: how to determine OID of the row I just inserted???

Поиск
Список
Период
Сортировка
От Joe Conway
Тема Re: how to determine OID of the row I just inserted???
Дата
Msg-id 3E4295E6.8040204@joeconway.com
обсуждение исходный текст
Ответ на Re: how to determine OID of the row I just inserted???  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
Tom Lane wrote:
> "Jules Alberts" <jules.alberts@arbodienst-limburg.nl> writes:
>>Something like lastval() IMHO is way too risky.
>
> currval() is what you want, and it is *not* risky.  Read the sequence
> documentation.

Tom's absolutely correct, of course. See:
http://www.us.postgresql.org/users-lounge/docs/7.3/postgres/functions-sequence.html

Another common solution I've used is something like:

create table person(pid serial, name text, aid int);
create table address(aid int, street text);
create sequence address_seq;

Then in PHP (or whatever) do:
     select nextval('address_seq');
and put the value into a variable (let's say you get back 42). Now you can do:

insert into person (name, aid) values ('John Doe', 42);
insert into address values (42, 'Penny Lane');

HTH,

Joe


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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Crash Backend in 7.3.1
Следующее
От: Bruno Wolff III
Дата:
Сообщение: Re: Pg_dumpall problem