Skip site navigation (1) Skip section navigation (2)

Re: [BUG?] strange behavior in ALTER TABLE ... RENAME TO on inherited columns

From: KaiGai Kohei <kaigai(at)ak(dot)jp(dot)nec(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Thom Brown <thombrown(at)gmail(dot)com>, Alvaro Herrera <alvherre(at)commandprompt(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [BUG?] strange behavior in ALTER TABLE ... RENAME TO on inherited columns
Date: 2009-11-05 00:57:03
Message-ID: 4AF222DF.40702@ak.jp.nec.com (view raw or flat)
Thread:
Lists: pgsql-hackers
Tom Lane wrote:
> Thom Brown <thombrown(at)gmail(dot)com> writes:
>> 2009/11/4 Alvaro Herrera <alvherre(at)commandprompt(dot)com>:
>>> KaiGai Kohei wrote:
>>>> I think we should not allow to rename a column with attinhcount > 1.
> 
>>> I think we should fix ALTER TABLE to cope with multiple inheritance.
> 
>> I'd be interested to see how this should work.
> 
> Yeah.  I don't think a "fix" is possible, because there is no
> non-astonishing way for it to behave.  I think KaiGai is right that
> forbidding the rename is the best solution.

The attached patch forbids rename when the attribute is inherited
from multiple parents.

  postgres=# CREATE TABLE t1 (a int, b int);
  CREATE TABLE
  postgres=# CREATE TABLE t2 (b int, c int);
  CREATE TABLE
  postgres=# CREATE TABLE t3 (d int) INHERITS (t1, t2);
  NOTICE:  merging multiple inherited definitions of column "b"
  CREATE TABLE
  postgres=# SELECT * FROM t3;
   a | b | c | d
  ---+---+---+---
  (0 rows)

  postgres=# ALTER TABLE t1 RENAME b TO x;
  ERROR:  cannot rename multiple inherited column "b"


The regression test detected a matter in the misc test.

It tries to rename column "a" of "a_star" table, but it failed due to
the new restriction.

  --
  -- test the "star" operators a bit more thoroughly -- this time,
  -- throw in lots of NULL fields...
  --
  -- a is the type root
  -- b and c inherit from a (one-level single inheritance)
  -- d inherits from b and c (two-level multiple inheritance)
  -- e inherits from c (two-level single inheritance)
  -- f inherits from e (three-level single inheritance)
  --
  CREATE TABLE a_star (
      class       char,
      a           int4
  );

  CREATE TABLE b_star (
      b           text
  ) INHERITS (a_star);

  CREATE TABLE c_star (
      c           name
  ) INHERITS (a_star);

  CREATE TABLE d_star (
      d           float8
  ) INHERITS (b_star, c_star);

At the misc test,

  --- 242,278 ----
    ALTER TABLE c_star* RENAME COLUMN c TO cc;
    ALTER TABLE b_star* RENAME COLUMN b TO bb;
    ALTER TABLE a_star* RENAME COLUMN a TO aa;
  + ERROR:  cannot rename multiple inherited column "a"
    SELECT class, aa
       FROM a_star* x
       WHERE aa ISNULL;
  ! ERROR:  column "aa" does not exist
  ! LINE 1: SELECT class, aa
  !

It seems to me it is a case the regression test to be fixed up.
(We don't have any reasonable way to know whether a certain attribute
has a same source, or not.)

Any comments?
-- 
OSS Platform Development Division, NEC
KaiGai Kohei <kaigai(at)ak(dot)jp(dot)nec(dot)com>

Attachment: pgsql-renameatt-multiple-inheritance.patch
Description: text/x-patch (2.6 KB)

In response to

Responses

pgsql-hackers by date

Next:From: Tom LaneDate: 2009-11-05 01:34:02
Subject: Shall we just get rid of plpgsql's RENAME?
Previous:From: Tatsuo IshiiDate: 2009-11-05 00:22:59
Subject: Re: Architecture of walreceiver (Streaming Replication)

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group