Skip site navigation (1) Skip section navigation (2)

Re: Simple search question

From: Peter Dixon <biz(at)ptdixon(dot)globalnet(dot)co(dot)uk>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Simple search question
Date: 2000-06-13 11:25:09
Message-ID: 87hfaxkelm.fsf@ptdixon.globalnet.co.uk (view raw or flat)
Thread:
Lists: pgsql-sql
Alex <gliathit(at)ihug(dot)com(dot)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

In response to

Responses

pgsql-sql by date

Next:From: rocaelDate: 2000-06-13 12:11:40
Subject: dump from access to pg on linux
Previous:From: John McKownDate: 2000-06-13 10:59:13
Subject: Re: Simple search question

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group