ALTER COLUMN/logical column position

From: Andreas Pflug <pgadmin(at)pse-consulting(dot)de>
To: Hannu Krosing <hannu(at)tm(dot)ee>
Cc: pg(at)fastcrypt(dot)com, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, Neil Conway <neilc(at)samurai(dot)com>, Peter Eisentraut <peter_e(at)gmx(dot)net>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: ALTER COLUMN/logical column position
Date: 2003-11-19 23:38:28
Message-ID: 3FBBFEF4.9060806@pse-consulting.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hannu Krosing wrote:

>>To put it differently: a ALTER COLUMN command may never-ever change the
>>identifier of the column, i.e. attrelid/attnum.
>>
>>
>
>to be even more restirictive: ALTER COLUMN may never-ever change the
>type of the column, as this too may break some apps. Nah!
>
>
>
Yeah, and the data should be read only :-)

Seriously: Methinks that only a part of the -patches thread was turned
over to -hackers, some important parts are missing.

First, there are column type changes that don't need any
index/view/constraint recheck or data transformation at all, being of
the very popular class "hell, I need to stuff 12 bytes in my
varchar(10)". Some months ago, this was discussed, and there was
consense that binarily compatible types may be changed with few special
precautions (e.g. varchar(12) -> varchar(10) e.g. needs a check for
len<=10). As a consequence, this kind of column type change is
implemented in pgAdmin3".

Probably a large percentage of real life column type changes are such
binarily compatible ones, so it's senseful to handle them separately.

Second, column type changes needing a nontrivial cast function should be
implemented in a way that preserve attnum. This could be done like this:
- decompile dependent objects, and memorize them for later recreation
- ADD tmpCol, UPDATE tmpCol=col::newtype, DROP old column, cascading to
dependent objects, RENAME tmpCol (known stuff)
- restore old attnum, which is a simple UPDATE to pg_attribute at this stage
- recreate all dependent objects

Voila! No need for an additional attpos.

Regards,
Andreas

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2003-11-19 23:42:58 Re: Build farm
Previous Message Austin Gonyou 2003-11-19 23:17:50 Re: Commercial binary support?