From: Peter Dixon <biz@ptdixon.globalnet.co.uk>
To: pgsql-sql@postgresql.org
Subject: Re: Simple search question
Date: 13 Jun 2000 12:25:09 +0100
Message-ID: <87hfaxkelm.fsf@ptdixon.globalnet.co.uk> (raw)
References: <39457549.CEA07C63@ihug.com.au>
<slrn8kb2dm.3rr.newsuser@linux2.johnmckown.net>
<39459935.CCCEFDAA@ihug.com.au>
Alex <gliathit@ihug.com.au> writes:
<pasted from earlier post>
> Hi,
> after running a script which performs an insert, a new tuple is
> created, and a serial number is generated for it. I want to write the
> new tuple data back to the screen, including the new serial number.
> My question is, do I have to do a search for the tuple just inserted in
> order to get the data back again? I am thinking there must be a faster,
> more efficient way.
> Thanks,
> Alex
I had the same problem but was using Java, not PHP (I guess that
whatever I can do in JDBC, you can do in PHP ;-)).
SELECT last_value FROM <sequence>;
worked fine to retrieve the last-used serial number. I could have
used
SELECT i.* FROM <insert_table> i,<sequence> s WHERE i.serial=s.last_value;
to retrieve the tuple, but I didn't need to do this.
> This leads to another question. If someone adds another row during this,
> what will happen?
In JDBC I would turn off auto-commit mode, then commit after the
SELECT. This should ensure that the sequence doesn't get incremented
between INSERT and SELECT.
>
> Thanks,
> Alex
Hope this helps,
Peter
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: biz@ptdixon.globalnet.co.uk
Subject: Re: Simple search question
In-Reply-To: <87hfaxkelm.fsf@ptdixon.globalnet.co.uk>
References: <39457549.CEA07C63@ihug.com.au> <slrn8kb2dm.3rr.newsuser@linux2.johnmckown.net> <39459935.CCCEFDAA@ihug.com.au> <87hfaxkelm.fsf@ptdixon.globalnet.co.uk>
* 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