Re: Re: Re: Re: Rules, views, sequences and returned values

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Gregory Wood" <gregw(at)com-stock(dot)com>
Cc: "PostgreSQL-General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Re: Re: Re: Rules, views, sequences and returned values
Date: 2001-03-23 22:37:41
Message-ID: 10750.985387061@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Gregory Wood" <gregw(at)com-stock(dot)com> writes:
>> so i can't retrieve and use the existing current value for a
>> sequence unless i bump it one? me no grok.
>> </dense>

> The idea is to retrieve the value after it has been used. If you grab the
> currval() and someone else grabs a currval() before you use it... bad things
> happen. Better to do the insert and see what value you ended up with. If you
> really want to grab a sequence value, just do nextval() and then you can use
> that value explicitly for an insert or whatnot.

If you do want to know the last value assigned by *anyone*, you can do
select last_value from SEQUENCE;
Note however that this value may very well be obsolete milliseconds
after you read it. It should certainly not be presumed to have anything
to do with the last nextval() value your own process assigned, nor with
the next nextval() you will assign in the future. Offhand I can't see
that it has any real usefulness: if you think you need it, you are
likely doing things wrong.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-03-23 22:42:37 Re: Vacuum VS Vacuum Analyze
Previous Message Stephan Szabo 2001-03-23 22:33:20 Re: Re: Re: Rules, views, sequences and returned values