ADD COLUMN with PRIMARY KEY bug (was: I think this is a BUG?)

From: "Brendan Jurd" <direvus(at)gmail(dot)com>
To: pgsql-patches(at)postgresql(dot)org
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Richard Huxton" <dev(at)archonet(dot)com>, kaloyan(at)digsys(dot)bg
Subject: ADD COLUMN with PRIMARY KEY bug (was: I think this is a BUG?)
Date: 2008-04-24 19:07:18
Message-ID: 37ed240d0804241207rb1c785crf63522791805461c@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)sss(dot)pgh(dot)pa(dot)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 Content-Type Size
add-column-pk.diff text/plain 3.8 KB

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2008-04-24 19:13:42 Re: ADD COLUMN with PRIMARY KEY bug (was: I think this is a BUG?)
Previous Message Gregory Stark 2008-04-24 18:58:20 Re: Proposed patch - psql wraps at window width