New setval() call - Mailing list pgsql-hackers

From Bruce Momjian
Subject New setval() call
Date
Msg-id 200102101723.MAA04962@candle.pha.pa.us
Whole thread Raw
Responses Re: New setval() call  (Philip Warner <pjw@rhyme.com.au>)
List pgsql-hackers
I am inclinded to remove this open item:
New SQL function setval(seq,val,bool) for use in pg_dump (Philip)

The use of the 3rd parameter, 'iscalled', while used by pg_dump, is not
of general use, so we probably don't need to document it.  Is this valid?

Info on the new param is:

---------------------------------------------------------------------------

IRC the point of the nextval() is to ensure that the internal state of
the sequence is correct.  There's a bool "is_called" in the sequence
that means something like "I've been nextval()'d at least once", and the
only clean way to make that become set is to issue a nextval.  You can
watch the behavior by doing "select * from sequenceobject" between
sequence commands --- it looks like the first nextval() simply sets
is_called without changing last_value, and then subsequent nextval()s
increment last_value.  (This peculiar arrangement makes it possible
to have a starting value equal to MININT, should you want to do so.)
So pg_dump needs to make sure it restores the correct setting of both
fields.

This is pretty grotty because it looks like there's no way to clear
is_called again, short of dropping and recreating the sequence.
So unless you want to do that always, a data-only restore couldn't
guarantee to restore the state of a virgin sequence.


--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Re: pg_ctl default shutdown mode
Next
From: Bruce Momjian
Date:
Subject: Re: Re: [PATCHES] Fix for ODBC close