Re: lastval()

From: Dennis Bjorklund <db(at)zigo(dot)dhs(dot)org>
To: Neil Conway <neilc(at)samurai(dot)com>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: lastval()
Date: 2005-06-05 06:00:04
Message-ID: Pine.LNX.4.44.0506050750070.7072-100000@zigo.dhs.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers 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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Simon Riggs 2005-06-05 08:06:37 Re: WAL bypass for CTAS
Previous Message Dennis Bjorklund 2005-06-05 05:49:42 Re: lastval()

Browse pgsql-patches by date

  From Date Subject
Next Message Simon Riggs 2005-06-05 08:06:37 Re: WAL bypass for CTAS
Previous Message Dennis Bjorklund 2005-06-05 05:49:42 Re: lastval()