ADD COLUMN with PRIMARY KEY bug (was: I think this is a BUG?) - Mailing list pgsql-patches

From Brendan Jurd
Subject ADD COLUMN with PRIMARY KEY bug (was: I think this is a BUG?)
Date
Msg-id 37ed240d0804241207rb1c785crf63522791805461c@mail.gmail.com
Whole thread Raw
Responses Re: ADD COLUMN with PRIMARY KEY bug (was: I think this is a BUG?)  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: ADD COLUMN with PRIMARY KEY bug (was: I think this is a BUG?)  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-patches
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

The attached patch resolves the bug reported by Kaloyan Iliev [1] on -general.

The problem occurred when executing ALTER TABLE ... ADD COLUMN ...
PRIMARY KEY with no default clause, on a table with rows already
present.  The NOT NULL constraint was not enforced.  The bug has been
observed on (at least) 8.2, 8.3 and CVS HEAD.

The fix was to force evaluation of the NOT NULL constraint in
ATExecAddColumn in all cases where the parser indicated that the
column ought to be NOT NULL.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: http://getfiregpg.org

iD8DBQFIENpl5YBsbHkuyV0RApP6AKDdnZAA0LjSzh9XdiQt7K/cx4YOcQCgydHr
6BYSD2kVX2DP7LYgDHvzNdE=
=Yrmp
-----END PGP SIGNATURE-----

On Fri, Apr 25, 2008 at 3:46 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>  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
>

I realised that there's no reason for preparing a separate SetNotNull
subcommand anymore, now that ATExecAddColumn takes care of enforcing
the constraint, so I removed this special case.

I've also added a regression test for ADD COLUMN PRIMARY KEY.

Cheers,
BJ

[1] http://archives.postgresql.org/message-id/481040A2.7090203@digsys.bg

Attachment

pgsql-patches by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: 64-bit CommandIds
Next
From: Tom Lane
Date:
Subject: Re: ADD COLUMN with PRIMARY KEY bug (was: I think this is a BUG?)