X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id DFB6A329C7B for ; Wed, 15 Sep 2004 15:22:27 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 48280-09 for ; Wed, 15 Sep 2004 14:22:21 +0000 (GMT) Received: from ucsns.ucs.co.za (ucs.co.za [196.23.43.2]) by svr1.postgresql.org (Postfix) with ESMTP id 27626329C65 for ; Wed, 15 Sep 2004 15:22:19 +0100 (BST) Received: from localhost (localhost.localdomain [127.0.0.1]) by ucsns.ucs.co.za (Postfix) with ESMTP id 615622BD60; Wed, 15 Sep 2004 16:21:56 +0200 (SAST) Received: from ucsns.ucs.co.za ([127.0.0.1]) by localhost (ucsns.ucs.co.za [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 31568-10; Wed, 15 Sep 2004 16:21:46 +0200 (SAST) Received: from ucspost.ucs.co.za (mailgw1.ucs.co.za [196.23.43.253]) by ucsns.ucs.co.za (Postfix) with ESMTP id 4DF362BD45; Wed, 15 Sep 2004 16:21:46 +0200 (SAST) Received: from jhb.ucs.co.za (jhb.ucs.co.za [172.31.1.3]) by ucspost.ucs.co.za (Postfix) with ESMTP id 18218DAD54; Wed, 15 Sep 2004 16:22:10 +0200 (SAST) Received: from svb.ucs.co.za (svb.ucs.co.za [172.31.1.148]) by jhb.ucs.co.za (Postfix) with SMTP id 53269976CB; Wed, 15 Sep 2004 16:22:01 +0200 (SAST) Date: Wed, 15 Sep 2004 16:22:01 +0200 From: Stef To: Andrew Sullivan Cc: pgsql-sql@postgresql.org Subject: Re: Preserving column order when recreating table. Message-Id: <20040915162201.13be5102@svb.ucs.co.za> In-Reply-To: <20040915131930.GA28290@phlogiston.dyndns.org> References: <20040915142445.06b60e3e@svb.ucs.co.za> <20040915131930.GA28290@phlogiston.dyndns.org> X-Mailer: Sylpheed-Claws 0.9.12 (GTK+ 1.2.10; i386-pc-linux-gnu) User-Agent: sillypheed-claws (anti-aliased) X-Face: GFoC95e6r)_TTG>n~=uFLojP=O~4W@Ms]>:.DMm/')(z3\Mwj^XP@? Q:3";lD.OM1"^mDu}2NJ@US:)dO:U*iY5EM50&Tx. X-Operating-System: sid X-X-X: _-^-_ Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at ucs.co.za X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/107 X-Sequence-Number: 18953 Andrew Sullivan mentioned : => I'm not sure why you want to do the former, but in any case, it's Because lazy people write inserts without specifying column names. => possible by creating a new table which has things the way you want; => select all the old data from the old table into the new table (using => the column names to get everything in the order you like, of course), I like this idea, but each database may have a different table definition for the same table, and if I want to automate this, I need to figure out the column names on the fly. => and then rename the old table, rename the new table to the old table => name, and drop the old table if you like. I think I've got the solution now. I'll do it in two steps. Fist add/drop all the columns that are not there/not supposed to be there, and in the second step do what you suggested. Thanks!! Kind Regards Stefan