Using curr_val Wisely

From: Jeff Waugh <jdub(at)aphid(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Using curr_val Wisely
Date: 2000-07-12 11:24:07
Message-ID: 20000712212407.A17561@aphid.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all,

I've got one daft question, and one good one...

Good One:

I'm using curr_val('blah_id_seq') in a transaction like so: (in pseudo SQL)

BEGIN;
INSERT INTO blah;
INSERT INTO foo (currval('blah_id_seq'));
COMMIT;

So the second insert requires the primary key of the first table as a
reference.

In the documentation, it says that even when there's multiple users, the
back end essentially guarantees that curr_val will work in this case. How
does it distinguish? Within the transaction, connection or something else?

Just wondering so I don't stuff anything up too badly! :)

Daft One:

This would be asked all the time, I'm sure. If I want to return the primary
key, or oid of the inserted record. The best way I can figure to do that now
is by selecting curr_val('blah_id_seq') at the end of this transaction
(which is why I asked the above question, because I'd like to be sure it
returns the id I think it should!)

For some reason, I can't get the postgres interface in PHP to return the
oid... But I'm more interested in doing this as a transaction anyway. :)

- Jeff

-- jdub(at)aphid(dot)net --------------------------------- http://linux.conf.au/ --

linux.conf.au - coming to Sydney in January 2001

Installing Linux Around Australia - http://linux.org.au/installfest/

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Sean Weissensee 2000-07-12 11:43:52 Re: PostgreSQL and Access (via ODBC)
Previous Message Giles Lean 2000-07-12 10:31:57 Re: psql and Gnu readline