Re: lastval() - Mailing list pgsql-patches

From Dennis Bjorklund
Subject Re: lastval()
Date
Msg-id Pine.LNX.4.44.0506050750070.7072-100000@zigo.dhs.org
Whole thread Raw
In response to Re: lastval()  (Neil Conway <neilc@samurai.com>)
Responses Re: lastval()
List pgsql-patches
On Thu, 19 May 2005, Neil Conway wrote:

> > +                  errmsg("currval of sequence with OID %d is not yet defined in this session",
> > +                         last_used_seq->relid)));
>
> See above; however, when will this error actually be invoked? (The
> comment is wrong, as last_used_seq won't be defined if nextval has not
> been called.)

Right, it shouldn't be called. It's only there because I kept all the
error cases from currval().

> > + static void
> > + acquire_share_lock (Relation seqrel,
> > +                     SeqTableData *data)
>
> Confusing SeqTable and SeqTableData * is bad style. I personally don't
> like putting pointers into typedefs, but since the PG code does this,
> SeqTable should be used consistently rather than SeqTableData *. The
> same applies to the definition of "last_used_seq".

The reason why I use SeqTableData * is that this function and
last_used_seq is not a list like the SeqTable is but it's a pointer to a
single element in a SeqTable.

To me SeqTable semantically represents a linked list while SeqTableData is
one cell in the list and I wanted to make that visible in the types I
used. But whatever convention is used in the rest of pg should be
followed.

> Comments on behavior:
>
> neilc=# select setval('foo', 500);
>   setval
> --------
>      500
> (1 row)
>
> neilc=# select lastval();
>   lastval
> ---------
>       500
> (1 row)
>
> I'm not sure it's necessarily _wrong_ to update lastval() on both setval
> and nextval, but if that's the behavior we're going to implement, it
> should surely be documented.

It's how currval works. You can do setval() on a sequence and then
currval() is defined.

> neilc=# create sequence bar ; select nextval ('bar') ; drop sequence bar;
> CREATE SEQUENCE
>   nextval
> ---------
>         1
> (1 row)
>
> DROP SEQUENCE
> neilc=# select lastval();
> ERROR:  XX000: could not open relation with OID 16389
>
> Needs a friendlier error message.

True.

--
/Dennis Björklund


pgsql-patches by date:

Previous
From: Dennis Bjorklund
Date:
Subject: Re: lastval()
Next
From: Simon Riggs
Date:
Subject: Re: WAL bypass for CTAS