Re: Resetting a sequence's last value...

From: Sean Chittenden <sean(at)chittenden(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Shridhar Daithankar <shridhar_daithankar(at)persistent(dot)co(dot)in>, pgsql-general(at)postgresql(dot)org
Subject: Re: Resetting a sequence's last value...
Date: 2003-04-27 21:00:53
Message-ID: 20030427210053.GO35599@perrin.int.nxad.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> > Thoughts? I got a post offlist suggesting writing a C function,
> > but that's pretty dependent on the backend and would have to be
> > recompiled from version to version, something I'm not too wild
> > about. -sc
>
> What would seem logical to me is using the iscalled parameter to
> setval to determine this. If you call setval('seq', 1, false), I
> think it would be reasonable for the currval('seq') to be undefined
> until nextval('seq') or setval with iscalled=true is called.

setval:
Reset the sequence object's counter value. The two-parameter
form sets the sequence's last_value field to the specified
value and sets its is_called field to true, meaning that the
next nextval will advance the sequence before returning a
value. In the three-parameter form, is_called may be set
either true or false. If it's set to false, the next nextval
will return exactly the specified value, and sequence
advancement commences with the following nextval.

That gives me an idea for the API, however. If the 2nd parameter is
NULL, it could reset is_called without changing the value. In all
situations, I must maintain that a transaction ID is unique to the
entire database and must always be the case.

SELECT setval('txn_id_seq', NULL);

Hrm... I may look into this later this week if something interesting
doesn't pop up or someone else doesn't beat me to the punch. -sc

--
Sean Chittenden

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Egyud Csaba 2003-04-28 01:05:23 Re: Returning with a userd defined type (PL/pgSQL)
Previous Message Tom Lane 2003-04-27 20:54:03 Re: Resetting a sequence's last value...