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