PLSQL Question regarding multiple inserts

Lists: pgsql-sql
From: "Humble Geek" <humblegeek(at)rogers(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: PLSQL Question regarding multiple inserts
Date: 2004-02-25 03:56:22
Message-ID: G1V_b.53$Yf.7@twister01.bloor.is.net.cable.rogers.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Hi all. Quick and perhaps silly question, but...

I am using Pg 7.3. I am writing a function using pgplsql. This function will
perform multiple inserts. Let's say two of the inserts are as follows:

-- id is primary key
insert into users (id, username) values (nextval('someSeq'),'somename');

-- id is also a PK
insert into log (id, uid, message) values (nextval('someOtherSeq'),XXX,'New
Account');

Assume XXX is the id from the first insert. How do I get that number? Not
currval('someSeq') - 'cause someone else may have performed an insert - but
the id for that specific insert.

Thanks,

HG


From: "V i s h a l Kashyap (at) [Sai Hertz And Control Systems]" <sank89(at)sancharnet(dot)in>
To: Humble Geek <humblegeek(at)rogers(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: PLSQL Question regarding multiple inserts
Date: 2004-03-01 04:17:50
Message-ID: 4042B96E.5080808@sancharnet.in
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Dear Humble Geek ,

>-- id is primary key
>insert into users (id, username) values (nextval('someSeq'),'somename');
>-- id is also a PK
>insert into log (id, uid, message) values (nextval('someOtherSeq'),XXX,'New
>Account');
>Assume XXX is the id from the first insert. How do I get that number? Not
>currval('someSeq') - 'cause someone else may have performed an insert
>
>
Nop,
If the insert and later on

currval('someSeq') is called inside the same function

currval will only return the current value that has been effected by the
first insert made.

--
Best Regards,
Vishal Kashyap
Director / Lead Developer,
Sai Hertz And Control Systems Pvt Ltd,
http://saihertz.rediffblogs.com
Jabber IM: vishalkashyap(at)jabber(dot)org
ICQ : 264360076
Yahoo IM: mailforvishal(at)yahoo(dot)com
-----------------------------------------------
You yourself, as much as anybody in the entire
universe, deserve your love and affection.
- Buddha
---------------
pgsql=# select marital_status from vishals_life;

marital_status
------------------
Single not looking

1 Row(s) affected

___
//\\\
( 0_0 )
----------------o0o-----o0o---------------------