Re: last inserted raw (identity)

From: nolan(at)celery(dot)tssi(dot)com
To: kleptog(at)svana(dot)org
Cc: ron(dot)l(dot)johnson(at)cox(dot)net (Ron Johnson), pgsql-general(at)postgresql(dot)org (postgresql)
Subject: Re: last inserted raw (identity)
Date: 2003-08-02 05:22:28
Message-ID: 20030802052229.8727.qmail@celery.tssi.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2003-08-02 06:11:40 Re: plPHP -- sort of an announcement.. but not commercial
Previous Message Joshua D. Drake 2003-08-02 05:17:45 Re: plPHP -- sort of an announcement.. but not commercial