Re: [GENERAL] PL/pgSQL help
От | Tim Joyce |
---|---|
Тема | Re: [GENERAL] PL/pgSQL help |
Дата | |
Msg-id | 00ac01beadc4$d98722e0$0201a8c0@po.HOOP обсуждение исходный текст |
Список | pgsql-general |
> MH> Question 2: > MH> is there a way to get the value of the newly assigned primary key > MH> after an insert? (rather then following the insert with a select) > > MH> e.g. (this would be nice if it worked (networkID is the PKey)) > MH> INSERT into Network (parentID, networkName) values (pid, mname); > MH> netid := new.networkID; > >Yes. 'serial' type implements as 'int' type for field and sequence, >which mane is <tablename>_<fieldname>_seq. So you can do this: > >INSERT into Network (parentID, networkName) values (pid, mname); >netid := Network_networkID_seq.last_value; Just so I can clarify this, does it work "multi-user". eg if this was the sequence of events: user 1: INSERT into Network (parentID, networkName) values (pid1, mname1); user 2: INSERT into Network (parentID, networkName) values (pid2, mname2); user 1: netid1 := Network_networkID_seq.last_value; would user 1 be given the correct id value? (assuming we maintain the connection). btw, I'm using java for my midleware cheers timj tim@hoop.co.uk
В списке pgsql-general по дате отправления: