Re: Re: Re: Rules, views, sequences and returned values
От | Stephan Szabo |
---|---|
Тема | Re: Re: Re: Rules, views, sequences and returned values |
Дата | |
Msg-id | Pine.BSF.4.21.0103231417120.47794-100000@megazone23.bigpanda.com обсуждение исходный текст |
Ответ на | Re: Re: Re: Rules, views, sequences and returned values (will trillich <will@serensoft.com>) |
Список | pgsql-general |
On Fri, 23 Mar 2001, 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... But, that value can't be guaranteed to be meaningful for other than the instant that you got it. One instant later you don't know it's meaningful (ie, still the current value of the sequence). What would ringo do with that information anyway? Conversely, what about if I've inserted something and then someone else did as well? I want to be able to get the value the sequence gave me. The point of the sequence is to be able get a unique value for inserting and to be able to retrieve that value, not that the sequences always succeed on that (rules and triggers can screw that up), but it's close.
В списке pgsql-general по дате отправления: