pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
(no subject)
2+ messages / 2 participants
[nested] [flat]

* (no subject)
@ 2000-04-19 09:34  Vladimir V. Zolotych <gsmith@eurocom.od.ua>
  0 siblings, 1 reply; 2+ messages in thread

From: Vladimir V. Zolotych @ 2000-04-19 09:34 UTC (permalink / raw)
  To: Andrew Perrin - Demography <aperrin@demog.berkeley.edu>; +Cc: pgsql-admin

> .........  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=....");





^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* RE:
@ 2000-04-19 11:41  Rainer Mager <rmager@vgkk.co.jp>
  parent: Vladimir V. Zolotych <gsmith@eurocom.od.ua>
  0 siblings, 0 replies; 2+ messages in thread

From: Rainer Mager @ 2000-04-19 11:41 UTC (permalink / raw)
  To: pgsql-admin


Does anyone know of a good way to do something similar in Java (JDBC)
connected to Postgres?

Thanks,

--Rainer


> -----Original Message-----
> From: pgsql-admin-owner@hub.org
> [mailto:pgsql-admin-owner@hub.org]On Behalf Of Vladimir V. Zolotych
> Sent: Wednesday, April 19, 2000 6:34 PM
> To: Andrew Perrin - Demography
> Cc: pgsql-admin@postgresql.org
> Subject: [ADMIN]
>
>
> > .........  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=....");
>
>
>




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2000-04-19 11:41 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-04-19 09:34  Vladimir V. Zolotych <gsmith@eurocom.od.ua>
2000-04-19 11:41 ` RE: Rainer Mager <rmager@vgkk.co.jp>

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