Обсуждение: Re: [GENERAL] PL/pgSQL help

Поиск
Список
Период
Сортировка

Re: [GENERAL] PL/pgSQL help

От
"Tim Joyce"
Дата:
> 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