pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Vladimir V. Zolotych <gsmith@eurocom.od.ua>
To: Andrew Perrin - Demography <aperrin@demog.berkeley.edu>
Cc: pgsql-admin@postgresql.org
Date: Wed, 19 Apr 2000 13:34:15 +0400
Message-ID: <38FD7D97.A683EE35@eurocom.od.ua> (raw)

> .........  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 <martin@chasm.org>) 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=....");





view thread (2+ messages)  latest in thread

Message-ID: <38FD7D97.A683EE35@eurocom.od.ua>
Permalink:  ../38FD7D97.A683EE35@eurocom.od.ua/
Also on:    postgresql.org/message-id/38FD7D97.A683EE35@eurocom.od.ua

 · 

reply

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-admin@postgresql.org
  Cc: gsmith@eurocom.od.ua, aperrin@demog.berkeley.edu
  Subject: Re: 
  In-Reply-To: <38FD7D97.A683EE35@eurocom.od.ua>
  References: <38FD7D97.A683EE35@eurocom.od.ua>

* 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