Received: from Main.eurocom.od.ua (root@Main.EuroCom.Od.UA [212.15.128.6]) by hub.org (8.9.3/8.9.3) with ESMTP id GAA58594 for ; Wed, 19 Apr 2000 06:37:35 -0400 (EDT) (envelope-from gsmith@eurocom.od.ua) Received: from eurocom.od.ua (TI.Com.Od.UA [212.15.128.36]) by Main.eurocom.od.ua (8.10.0/8.10.0) with ESMTP id e3JAavK18539; Wed, 19 Apr 2000 13:37:01 +0300 Message-ID: <38FD7D97.A683EE35@eurocom.od.ua> Date: Wed, 19 Apr 2000 13:34:15 +0400 From: "Vladimir V. Zolotych" X-Mailer: Mozilla 4.5 [en] (WinNT; I) X-Accept-Language: en,ru MIME-Version: 1.0 To: Andrew Perrin - Demography CC: pgsql-admin@postgresql.org Content-Type: text/plain; charset=koi8-r Content-Transfer-Encoding: 7bit X-Archive-Number: 200004/72 > ......... In my case, I used currval(). Basically: > > SELECT currval('table_field_seq'); > > will return the most recently assigned value to the field *by the > current > backend* which means: > > - There's no danger of a race condition (another user creating a > record in > the time between your creating the record and calling currval); BUT > - You must be using the same backend as you did on the creation. This is the way I've used before. It seems the the better way (thanks to Charles Martin ) is: 1) Do INSERT PGresult* res = PQexec(conn, "INSERT......") 2) Get the OID of the just inserted record e.g const char* oid = PQoidStatus(res) 3) Select the id of this record: res = PQexec(conn, "SELECT id .... WHERE OID=....");