Re: last inserted raw (identity) - Mailing list pgsql-general

From nolan@celery.tssi.com
Subject Re: last inserted raw (identity)
Date
Msg-id 20030802052229.8727.qmail@celery.tssi.com
Whole thread Raw
In response to Re: last inserted raw (identity)  (Martijn van Oosterhout <kleptog@svana.org>)
Responses Re: last inserted raw (identity)  (Martijn van Oosterhout <kleptog@svana.org>)
List pgsql-general
> > In short, I think the answer to the original question is that there is no
> > reliable way to find out what the last record inserted was.
>
> It returns the last record *you* entered. If you want the last record
> entered by anyone (committed ofcourse), you'd use order by x desc limit 1.

I agree that currval() would return the last record *I* inserted, but
I don't understand how an order by clause would always return the last
record that *ANYBODY* inserted.  (And I thought that was the original
question, but perhaps I am mis-remembering it at this point.)

If another user has a cache of 10 sequence values, there's no way
for me to know that.  Thus when the other user inserts a record using
one of those cached sequence values, it could be either higher or
lower than the sequence value in MY most recently inserted record.
(I think it could be higher only if I also have my own cache of sequence
values, assuming that the sequence never wraps.)
--
Mike Nolan

pgsql-general by date:

Previous
From: "Joshua D. Drake"
Date:
Subject: Re: plPHP -- sort of an announcement.. but not commercial
Next
From: Bruce Momjian
Date:
Subject: Re: plPHP -- sort of an announcement.. but not commercial