Received: from ece.rice.edu (ece.rice.edu [128.42.4.34]) by postgresql.org (8.11.3/8.11.4) with ESMTP id f9TNGUP21873 for ; Mon, 29 Oct 2001 18:16:30 -0500 (EST) (envelope-from reedstrm@rice.edu) Received: from localhost (localhost [127.0.0.1]) by ece.rice.edu (Postfix) with ESMTP id EF7E068A59 for ; Mon, 29 Oct 2001 17:16:27 -0600 (CST) Received: from wallace.ece.rice.edu (wallace.ece.rice.edu [128.42.12.154]) by ece.rice.edu (Postfix) with ESMTP id 3D17168A17 for ; Mon, 29 Oct 2001 17:16:27 -0600 (CST) Received: from reedstrm by wallace.ece.rice.edu with local (Exim 3.22 #1 (Debian)) id 15yLdr-0006VZ-00 for ; Mon, 29 Oct 2001 17:16:27 -0600 Date: Mon, 29 Oct 2001 17:16:27 -0600 From: "Ross J. Reedstrom" To: pgsql-admin@postgresql.org Subject: Re: Code to automatically refresh sequences after loading data? Message-ID: <20011029171627.B24888@rice.edu> Mail-Followup-To: "Ross J. Reedstrom" , pgsql-admin@postgresql.org References: <9rerbg$25uq$1@news.tht.net> <20011029131815.B23138@rice.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20011029131815.B23138@rice.edu> User-Agent: Mutt/1.3.18i X-Virus-Scanned: by AMaViS snapshot-20010714 X-Archive-Number: 200110/254 X-Sequence-Number: 2498 On Mon, Oct 29, 2001 at 01:18:15PM -0600, Ross J. Reedstrom wrote: Need to fix that: I was short a right paren: select 'SELECT setval(''"'||cs.relname||'"'', max("'||attname||'")) FROM "'||c.relname||'";' from pg_class c, pg_class cs, pg_attribute a, pg_attrdef d where cs.relkind = 'S' and d.adsrc ~ cs.relname and c.oid = a.attrelid and c.oid = d.adrelid and d.adnum = a.attnum; now you can do (in psql): bioinfo=# \t Showing only tuples. bioinfo=# select 'SELECT setval(''"'||cs.relname|| '"'', max("'||attname||'")) FROM "'||c.relname||'";' from pg_class c, pg_class cs, pg_attribute a, pg_attrdef d where cs.relkind = 'S' and d.adsrc ~ cs.relname and c.oid = a.attrelid and c.oid = d.adrelid and d.adnum = a.attnum \g fix-serial.sql bioinfo=# \i fix-serial.sql 77 78 17 bioinfo=# i.e. use SQL to generate the SQL into a file, then read the commands back in from that file. Note that since this grovels around in systemtables, it can break with version changes. Ross -- Ross Reedstrom, Ph.D. reedstrm@rice.edu Executive Director phone: 713-348-6166 Gulf Coast Consortium for Bioinformatics fax: 713-348-6182 Rice University MS-39 Houston, TX 77005