Re: reinitialize a sequence? - Mailing list pgsql-sql

From Ross J. Reedstrom
Subject Re: reinitialize a sequence?
Date
Msg-id 20001205112737.B13143@rice.edu
Whole thread Raw
In response to Re: reinitialize a sequence?  ("Ross J. Reedstrom" <reedstrm@rice.edu>)
List 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@rice.edu> 
NSBRI Research Scientist/Programmer
Computer and Information Technology Institute
Rice University, 6100 S. Main St.,  Houston, TX 77005


pgsql-sql by date:

Previous
From: "Edmar Wiggers"
Date:
Subject: Using SELECT as DDL/DML statement is wrong (was RE: reinitialize a sequence?)
Next
From: Michael Ansley
Date:
Subject: RE: Using SELECT as DDL/DML statement is wrong (was RE: rei nitialize a sequence?)