Skip site navigation (1) Skip section navigation (2)

Re: Preserving column order when recreating table.

From: Andrew Sullivan <ajs(at)crankycanuck(dot)ca>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Preserving column order when recreating table.
Date: 2004-09-15 14:42:12
Message-ID: 20040915144212.GA28600@phlogiston.dyndns.org (view raw or flat)
Thread:
Lists: pgsql-sql
On Wed, Sep 15, 2004 at 04:22:01PM +0200, Stef wrote:
> 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.

Ugh.  Sorry to say so, but this sounds to me really a lot like the
cure is worse than the disease.  The answer to "Bob did something
incredibly stupid" is not "We'll bend ourselves into contortions to
support it."  (This is not to say I don't sympathise.  You wouldn't
believe how much I do.)

> => 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.

That's a little trickier, but you could figure it out with some
queries from pg_class and pg_attribute. 

> Thanks!!

No problem, but I think you need to have a long talk with your
developers.  Possibly while holding a baseball bat or something. 
Furrfu.  This no-column-names thing is bound to bite you some day,
and probably in tender bits where such bites would be unpleasant.

A

-- 
Andrew Sullivan  | ajs(at)crankycanuck(dot)ca
This work was visionary and imaginative, and goes to show that visionary
and imaginative work need not end up well. 
		--Dennis Ritchie

In response to

pgsql-sql by date

Next:From: StefDate: 2004-09-15 15:07:00
Subject: Re: Preserving column order when recreating table.
Previous:From: StefDate: 2004-09-15 14:22:01
Subject: Re: Preserving column order when recreating table.

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group