currval returns error unless nextval has been called at least once in the
session.
I use <seq>.last_value
Perhaps I'm fooling myself that the latter is doing what I think, but it
seems to work fine and doesn't require an initial call to nextval.
I too thought that OID was always unique. That is not true?
--rob
----- Original Message -----
From: "Oliver Elphick" <olly@lfix.co.uk>
To: "Florent Guillaume" <efgeor@noos.fr>
Cc: <pgsql-general@postgresql.org>
Sent: Friday, January 19, 2001 5:27 PM
Subject: Re: Re: is PG able to handle a >500 GB Database?
> Florent Guillaume wrote:
> >> Unless your application logic tries to use OIDs as row identifiers,
> >> duplicate OIDs in user tables are not a problem.
> >
> >Hmmm, that means that the following, which I use, is not strictly
correct :
> >
> >create table t1 (recordid SERIAL PRIMARY KEY, val INT4, name TEXT);
> >... much later ...
> >insert into t1 (val, name) values (3465, 'blah');
> >-- PHP application gets $lastoid for this insert
> >select recordid from t1 where oid = $lastoid;
> >-- PHP application now hast the recordid that was created.
> >
> >Because the last select could return several lines.
> >
> >What would be the correct idiom ? Explicitly use nextval ? That pretty
> >defeats the point of SERIAL, no ?
>
> SELECT currval('t1_recordid_seq');
>
> currval is guaranteed to return the value that the sequence has just put
> into recordid.
>
> --
> Oliver Elphick Oliver.Elphick@lfix.co.uk
> Isle of Wight http://www.lfix.co.uk/oliver
> PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47 6B 7E 39 CC 56 E4 C1 47
> GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
> ========================================
> "The LORD is my strength and song, and he is become my
> salvation; he is my God, and I will prepare him an
> habitation; my father's God, and I will exalt him."
> Exodus 15:2
>
>
>