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

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 (view raw or flat)
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: add-column-pk.diff
Description: text/plain (3.8 KB)

Responses

pgsql-patches by date

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

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