From: Eckhard Hoeffner <e-hoeffner@fifoost.org>
To: SQL PostgreSQL <pgsql-sql@postgresql.org>
Subject: Using LASTOID in one query
Date: Mon, 20 May 2002 16:08:36 +0200
Message-ID: <20020520140835.GA6211@fifoost.org> (raw)
Is there a possibility to use the last OID from PHP within one
query? I have two tables like the following:
table_a:
number1 serial PRIMARY KEY
a_text text
table_b:
number1 integer REFERENCES table_a,
b_text text
I am retrieving data like
a_text = something
b_text = something else
With psql I would do the following:
BEGIN;
INSERT INTO table_a (a_text) VALUES ('something');
INSERT 224490 1
SELECT number1 FROM table_a WHERE oid = 224490;
number1
-------
9
(1 row)
INSERT INTO table_b (number1, b_text) VALUES (9, 'something else');
INSERT 224491 1;
COMMIT;
If I am using php, the only solution I know is:
1. make the first INSERT, execute it
2. get the last oid and make the next query, execute it
3. make the second INSERT
This are 3 queries and I can not do it within a transaction.
--
--//--\\--
Eckhard Hoeffner
e-hoeffner@fifoost.org
Tal 44
D-80331 München
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: e-hoeffner@fifoost.org
Subject: Re: Using LASTOID in one query
In-Reply-To: <20020520140835.GA6211@fifoost.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox