Обсуждение: Is it possible to have multiple names for a column?

Поиск
Список
Период
Сортировка

Is it possible to have multiple names for a column?

От
felix@crowfix.com
Дата:
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

Re: Is it possible to have multiple names for a column?

От
Tom Lane
Дата:
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

Re: Is it possible to have multiple names for a column?

От
Scott Marlowe
Дата:
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.

Re: Is it possible to have multiple names for a column?

От
Bernhard Weisshuhn
Дата:
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