Is it possible to have multiple names for a column?

Lists: pgsql-general
From: felix(at)crowfix(dot)com
To: pgsql-general(at)postgresql(dot)org
Subject: Is it possible to have multiple names for a column?
Date: 2006-09-14 19:18:05
Message-ID: 20060914191805.GA10037@crowfix.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

We have a need to rename some columns, but since we can't update both
the database and the programs instantly, we'd like to temporarily
assign both names to the same column while the updates are in
progress. Something like this would be super nifty :-)

ALTER TABLE howdy_doody ADD NAME xyzzy TO COLUMN plugh;

I am pretty certain no such SQL command exists. But is it possible to
do something sneaky to the internal tables so that two names point to
the same columnand everything just works? Everything meaning updates,
inserts, etc, not further ALTER TABLE and so on.

--
... _._. ._ ._. . _._. ._. ___ .__ ._. . .__. ._ .. ._.
Felix Finch: scarecrow repairman & rocket surgeon / felix(at)crowfix(dot)com
GPG = E987 4493 C860 246C 3B1E 6477 7838 76E9 182E 8151 ITAR license #4933
I've found a solution to Fermat's Last Theorem but I see I've run out of room o


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: felix(at)crowfix(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Is it possible to have multiple names for a column?
Date: 2006-09-14 19:29:46
Message-ID: 2264.1158262186@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

felix(at)crowfix(dot)com writes:
> I am pretty certain no such SQL command exists. But is it possible to
> do something sneaky to the internal tables so that two names point to
> the same columnand everything just works?

No ... at least not for usefully large values of "work".

You might be able to do something involving a view that renames the
column in question, with as-yet-unconverted clients made to reference
the view. Offhand I'm not convinced that's easier than just fixing the
clients though ...

regards, tom lane


From: Scott Marlowe <smarlowe(at)g2switchworks(dot)com>
To: felix(at)crowfix(dot)com
Cc: pgsql general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Is it possible to have multiple names for a column?
Date: 2006-09-14 19:44:55
Message-ID: 1158263095.24726.21.camel@state.g2switchworks.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Thu, 2006-09-14 at 14:18, felix(at)crowfix(dot)com wrote:
> We have a need to rename some columns, but since we can't update both
> the database and the programs instantly, we'd like to temporarily
> assign both names to the same column while the updates are in
> progress. Something like this would be super nifty :-)
>
> ALTER TABLE howdy_doody ADD NAME xyzzy TO COLUMN plugh;
>
> I am pretty certain no such SQL command exists. But is it possible to
> do something sneaky to the internal tables so that two names point to
> the same columnand everything just works? Everything meaning updates,
> inserts, etc, not further ALTER TABLE and so on.

You could create a view, make the two outside names reference the one
inside name, and create a trigger to update based on which one if given
data and throw an error if you try to update both columns at the same
time.

Sounds like a lot of work though.


From: Bernhard Weisshuhn <bkw(at)weisshuhn(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Is it possible to have multiple names for a column?
Date: 2006-09-14 20:42:52
Message-ID: 20060914204251.GA12470@weisshuhn.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Thu, Sep 14, 2006 at 12:18:05PM -0700, felix(at)crowfix(dot)com wrote:

> We have a need to rename some columns, but since we can't update both
> the database and the programs instantly, we'd like to temporarily
> assign both names to the same column while the updates are in
> progress. Something like this would be super nifty :-)
>
> ALTER TABLE howdy_doody ADD NAME xyzzy TO COLUMN plugh;

If the clients only read the column, you could just add the new
column and create triggers that copy the value from the other column on
any modification.
Later you drop the old column and the triggers.

Maybe an approch based on rules might work? Dunno, haven't used them yet.

regards,
bkw