From: | "Eric G(dot) Miller" <egm2(at)jps(dot)net> |
---|---|
To: | PostgreSQL-General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Re: Re: Rules, views, sequences and returned values |
Date: | 2001-03-23 22:33:07 |
Message-ID: | 20010323143307.A23691@calico.local |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Fri, Mar 23, 2001 at 04:11:56PM -0600, will trillich wrote:
> On Fri, Mar 23, 2001 at 12:23:35PM -0500, Gregory Wood wrote:
> > > i'm sure there's a reason for this--
> > >
> > > psql=> select currval('mytable_afield_seq') ;
> > > ERROR: mytable_afield_seq.currval is not yet defined in this session
> > >
> > > but i'll be darned if i can figure out what it is. (after one
> > > call to "nextval()" currval() works fine, of course.) someone hit
> > > me with a clue stick!
> >
> > currval() is the value last used by the backend, not by the database.
> > Meaning that you have to actually use the sequence before the backend has a
> > value to retrieve. That means either doing a nextval() or doing an INSERT
> > (which implicitly performs the nextval() ).
>
> <dense mode=on>
> seems like the backend (server?) would know the current value of
> a sequence, since it has to get it, then add one to it, to get
> the next one in line. if george inserts a record, i'd think that
> ringo would be able to see the current counter afterwards,
> independent of session...
>
> so i can't retrieve and use the existing current value for a
> sequence unless i bump it one? me no grok.
> </dense>
Hmm, I wonder if the currval() function could just do a
SELECT last_value FROM <sequence>;
if the nextval() has yet set the currval() context. I suppose there
could be problems with that approach.
Why would you want to get the last value of the sequence if you haven't
used it yet? Seems there'd be no context from a previous use of
nextval(), so what would you use the value for?
--
Eric G. Miller <egm2(at)jps(dot)net>
From | Date | Subject | |
---|---|---|---|
Next Message | Stephan Szabo | 2001-03-23 22:33:20 | Re: Re: Re: Rules, views, sequences and returned values |
Previous Message | Gregory Wood | 2001-03-23 22:28:24 | Re: Re: Re: Rules, views, sequences and returned values |