Re: [GENERAL] PL/pgSQL help

From: "Tim Joyce" <tim(at)hoop(dot)co(dot)uk>
To: "Mike Haberman" <mikeh(at)ncsa(dot)uiuc(dot)edu>, "Anatoly K(dot) Lasareff" <tolik(at)icomm(dot)ru>
Cc: <pgsql-general(at)postgreSQL(dot)org>
Subject: Re: [GENERAL] PL/pgSQL help
Date: 1999-06-03 13:08:07
Message-ID: 00ac01beadc4$d98722e0$0201a8c0@po.HOOP
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)hoop(dot)co(dot)uk

Browse pgsql-general by date

  From Date Subject
Next Message Lincoln Spiteri 1999-06-03 14:28:26 MSysConf grief
Previous Message Adriaan Joubert 1999-06-03 11:54:55 Parser or documentation bug?