Re: Re: Re: Re: Rules, views, sequences and returned values - Mailing list pgsql-general

From Tom Lane
Subject Re: Re: Re: Re: Rules, views, sequences and returned values
Date
Msg-id 10750.985387061@sss.pgh.pa.us
Whole thread Raw
In response to Re: Re: Re: Rules, views, sequences and returned values  ("Gregory Wood" <gregw@com-stock.com>)
List pgsql-general
"Gregory Wood" <gregw@com-stock.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

pgsql-general by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: Re: Re: Rules, views, sequences and returned values
Next
From: culley harrelson
Date:
Subject: performance of ORDER BY random()