Re: [GENERAL] I think this is a BUG? - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [GENERAL] I think this is a BUG?
Date
Msg-id 1424.1209059182@sss.pgh.pa.us
Whole thread Raw
In response to Re: [GENERAL] I think this is a BUG?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: [GENERAL] I think this is a BUG?  ("Brendan Jurd" <direvus@gmail.com>)
List pgsql-hackers
I wrote:
> So somehow the constraint-validation code isn't getting applied in
> this case.  I suspect you'll find it's a pretty localized fix.

I traced through this and found that for

alter table t1 add column f2 int not null;

transformAlterTableStmt will produce an AT_AddColumn subcommand
containing a ColumnDef with is_not_null = false, followed by an
AT_SetNotNull subcommand.  But for

alter table t1 add column f2 int primary key;

it produces an AT_AddColumn subcommand containing a ColumnDef with
is_not_null = true, followed by an AT_AddIndex subcommand.

This is not super consistent, and maybe should be cleaned up;
but the intent is perfectly clear in both cases so I think tablecmds.c
should be able to do the right thing with either.

It looks to me that the appropriate fix involves doing
tab->new_notnull |= colDef->is_not_null;

somewhere in ATExecAddColumn; but I haven't tested this much.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Gregory Stark
Date:
Subject: Re: Proposed patch - psql wraps at window width
Next
From: Bruce Momjian
Date:
Subject: Re: Proposed patch - psql wraps at window width