From: | "Vladimir V(dot) Zolotych" <gsmith(at)eurocom(dot)od(dot)ua> |
---|---|
To: | Andrew Perrin - Demography <aperrin(at)demog(dot)berkeley(dot)edu> |
Cc: | pgsql-admin(at)postgresql(dot)org |
Subject: | |
Date: | 2000-04-19 09:34:15 |
Message-ID: | 38FD7D97.A683EE35@eurocom.od.ua |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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(at)chasm(dot)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=....");
From | Date | Subject | |
---|---|---|---|
Next Message | Loïc TREGOUËT | 2000-04-19 10:14:07 | Postquel? |
Previous Message | Andrew Perrin - Demography | 2000-04-18 16:18:35 | Re: sequence |