Thread: Bug #951: Creating table fails if inherited table has no columns.

Bug #951: Creating table fails if inherited table has no columns.

From
pgsql-bugs@postgresql.org
Date:
Daniel Migowski (Mig-O@artis.uni-oldenburg.de) reports a bug with a severity of 3
The lower the number the more severe it is.

Short Description
Creating table fails if inherited table has no columns.

Long Description
Creating a table that inherits from another table with no colums an internal error is thrown. This is repeatable.
See the example for the error message.

Daniel Migowski


Version: 7.3.2r-7 (Debian package)
OS: Linux becks 2.4.19 #5 SMP Thu Mar 20 22:59:40 CET 2003 i686 unknown unknown GNU/Linux


Sample Code
TestDB=# create table mother ( );
CREATE TABLE
TestDB=# create table father ( father_id int4 );
CREATE TABLE
TestDB=# create table daughter ( ) inherits ( mother );
ERROR:  MemoryContextAlloc: invalid request size 0
TestDB=# create table son ( ) inherits ( father );
CREATE TABLE


No file was uploaded with this report

Re: Bug #951: Creating table fails if inherited table has no columns.

From
Tom Lane
Date:
pgsql-bugs@postgresql.org writes:
> Creating table fails if inherited table has no columns.

Good catch.  Here's the patch if you need it right away.

            regards, tom lane

*** src/backend/commands/tablecmds.c~    Mon Dec 16 13:39:56 2002
--- src/backend/commands/tablecmds.c    Mon Apr 21 11:20:02 2003
***************
*** 576,584 ****
           * newattno[] will contain the child-table attribute numbers for
           * the attributes of this parent table.  (They are not the same
           * for parents after the first one, nor if we have dropped
!          * columns.)
           */
!         newattno = (AttrNumber *) palloc(tupleDesc->natts * sizeof(AttrNumber));

          for (parent_attno = 1; parent_attno <= tupleDesc->natts;
               parent_attno++)
--- 576,585 ----
           * newattno[] will contain the child-table attribute numbers for
           * the attributes of this parent table.  (They are not the same
           * for parents after the first one, nor if we have dropped
!          * columns.)  +1 is to prevent error if parent has zero columns.
           */
!         newattno = (AttrNumber *)
!             palloc((tupleDesc->natts + 1) * sizeof(AttrNumber));

          for (parent_attno = 1; parent_attno <= tupleDesc->natts;
               parent_attno++)

Re: Bug #951: Creating table fails if inherited table has no columns.

From
"Mig-O"
Date:
_That_ was a fast fix !! :)

Thnx,
Mig-O