Re: reinitialize a sequence?

From: "Ross J(dot) Reedstrom" <reedstrm(at)rice(dot)edu>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: reinitialize a sequence?
Date: 2000-12-05 17:27:37
Message-ID: 20001205112737.B13143@rice.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Following up to myself:

There is in fact a bug in 7.0.2 that's been fixed in 7.0.3 which causes
my select below not to work. The name of the sequence is now stored
with double quotes around it, to handle the mixed case names problem,
so the query needs to look like (untested: note added double quote to
last where clause):

select 'SELECT setval(\'"' ||
substr(adsrc,10,(length(adsrc) - 17)) ||
'"\', max("' || attname || '")) FROM "' ||
relname || '";'
from pg_class c,
pg_attribute a,
pg_attrdef d
where c.oid=d.adrelid and
a.attrelid=c.oid and
d.adnum=a.attnum and
d.adsrc ~ ('nextval\\(\'"'||relname);

On Tue, Dec 05, 2000 at 10:10:12AM -0600, Ross J. Reedstrom wrote:
> On Mon, Dec 04, 2000 at 03:51:35PM -0800, Dan Lyke wrote:
> > Bruno Boettcher writes:
> > > is there a simple way to tell all sequences to take the max value +1 of
> > > their respective tables? (a bit like the vacuum command?)
> >
> > This is completely gross, but what I've done:
> >
>
> Hmm, what I usually do is something like:
>
> SELECT setval('tablename_serfield_seq',max(serfield)) FROM tablename;
>
>

Ross
--
Ross J. Reedstrom, Ph.D., <reedstrm(at)rice(dot)edu>
NSBRI Research Scientist/Programmer
Computer and Information Technology Institute
Rice University, 6100 S. Main St., Houston, TX 77005

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Sivagami . 2000-12-05 22:11:16 Foreign key constraint
Previous Message Edmar Wiggers 2000-12-05 16:49:33 Using SELECT as DDL/DML statement is wrong (was RE: reinitialize a sequence?)