Unix Technical Forum

Is it possible to have multiple names for a column?

This is a discussion on Is it possible to have multiple names for a column? within the Pgsql General forums, part of the PostgreSQL category; --> We have a need to rename some columns, but since we can't update both the database and the programs ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-09-2008, 11:24 AM
felix@crowfix.com
 
Posts: n/a
Default Is it possible to have multiple names for a column?

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@crowfix.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

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-09-2008, 11:24 AM
Tom Lane
 
Posts: n/a
Default Re: Is it possible to have multiple names for a column?

felix@crowfix.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

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-09-2008, 11:24 AM
Scott Marlowe
 
Posts: n/a
Default Re: Is it possible to have multiple names for a column?

On Thu, 2006-09-14 at 14:18, felix@crowfix.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.

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-09-2008, 11:24 AM
Bernhard Weisshuhn
 
Posts: n/a
Default Re: Is it possible to have multiple names for a column?

On Thu, Sep 14, 2006 at 12:18:05PM -0700, felix@crowfix.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

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:43 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com