Lists: | pgsql-hackers |
---|
From: | Luca Ferrari <fluca1978(at)infinito(dot)it> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | [OT] why not keeping the original column name in catalog after a drop? |
Date: | 2013-11-13 07:52:27 |
Message-ID: | CAKoxK+48=7tLkc=hFOWZ6U6JCS2iR6x-92ggM06rxpYc1qkmgg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Hi all,
when you drop a column on a table the pg_attribute is updated and the
name of the column is changed with an almost fixed identifier that
reports only the original column position:
/*
* Change the column name to something that isn't likely to conflict
*/
snprintf(newattname, sizeof(newattname),
"........pg.dropped.%d........", attnum);
namestrcpy(&(attStruct->attname), newattname);
I'm wondering what is the problem in placing the old/original name
after the "pg.dropped" prefix. I know that the tuple in pg_attribute
is temporary, but what are the possible conflicts the comment talks
about?
Thanks,
Luca
From: | Pavan Deolasee <pavan(dot)deolasee(at)gmail(dot)com> |
---|---|
To: | Luca Ferrari <fluca1978(at)infinito(dot)it> |
Cc: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: [OT] why not keeping the original column name in catalog after a drop? |
Date: | 2013-11-13 07:59:14 |
Message-ID: | CABOikdNpDCB_-aPs8-zKzs-k0bmW_f5-Jww0XWFaJQeKvD28Cw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Wed, Nov 13, 2013 at 1:22 PM, Luca Ferrari <fluca1978(at)infinito(dot)it> wrote:
>
>
> I'm wondering what is the problem in placing the old/original name
> after the "pg.dropped" prefix. I know that the tuple in pg_attribute
> is temporary, but what are the possible conflicts the comment talks
> about?
>
>
May be when a column with the same name is added and again dropped ? Of
course, we can have the attribute number and column name both to avoid
conflict.
Thanks,
Pavan
--
Pavan Deolasee
http://www.linkedin.com/in/pavandeolasee
From: | Andres Freund <andres(at)2ndquadrant(dot)com> |
---|---|
To: | Luca Ferrari <fluca1978(at)infinito(dot)it> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: [OT] why not keeping the original column name in catalog after a drop? |
Date: | 2013-11-13 08:00:11 |
Message-ID: | 20131113080011.GD5666@awork2.anarazel.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Hi,
On 2013-11-13 08:52:27 +0100, Luca Ferrari wrote:
> when you drop a column on a table the pg_attribute is updated and the
> name of the column is changed with an almost fixed identifier that
> reports only the original column position:
>
> /*
> * Change the column name to something that isn't likely to conflict
> */
> snprintf(newattname, sizeof(newattname),
> "........pg.dropped.%d........", attnum);
> namestrcpy(&(attStruct->attname), newattname);
>
> I'm wondering what is the problem in placing the old/original name
> after the "pg.dropped" prefix. I know that the tuple in pg_attribute
> is temporary, but what are the possible conflicts the comment talks
> about?
The old name might not fit there, attribute names have a relatively low
maximum length (64 by default), so we cannot always fit the entire old
name there.
Also, think about:
CREATE TABLE foo(cola int);
ALTER TABLE foo DROP COLUMN cola;
ALTER TABLE foo ADD COLUMN cola;
ALTER TABLE foo DROP COLUMN cola; -- should not error out
I don't really see much need for anything better than the current
solution, why is the old name interesting?
Greetings,
Andres Freund
--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
From: | Luca Ferrari <fluca1978(at)infinito(dot)it> |
---|---|
To: | Andres Freund <andres(at)2ndquadrant(dot)com> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: [OT] why not keeping the original column name in catalog after a drop? |
Date: | 2013-11-13 11:17:58 |
Message-ID: | CAKoxK+7FdDJoFc6PybkwuxMFirt7yY0iGWZdtP9cii4acsPZuQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Wed, Nov 13, 2013 at 9:00 AM, Andres Freund <andres(at)2ndquadrant(dot)com> wrote:
> The old name might not fit there, attribute names have a relatively low
> maximum length (64 by default), so we cannot always fit the entire old
> name there.
Thanks, I was guessing this.
>
> Also, think about:
> CREATE TABLE foo(cola int);
> ALTER TABLE foo DROP COLUMN cola;
> ALTER TABLE foo ADD COLUMN cola;
> ALTER TABLE foo DROP COLUMN cola; -- should not error out
Well, I was talking about appending the original column name, and
therefore the above should have been respectively pg.dropped.1.cola.
and pg.dropped.2.cola. Of course the original name is not very much
interesting, I was just curios about the conflicts.
Luca