Re: [GENERAL] I think this is a BUG?

From: "Brendan Jurd" <direvus(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [GENERAL] I think this is a BUG?
Date: 2008-04-24 16:47:39
Message-ID: 37ed240d0804240947u27d5fd10jd61abaaab9096d04@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Fri, Apr 25, 2008 at 2:27 AM, Tom Lane wrote:
> "Brendan Jurd" writes:
> > transformIndexConstraint sets the is_not_null flag on the ColumnDefs
> > associated with the primary key. That works great in a CREATE TABLE
> > context, but in ADD COLUMN, when we haven't created the column yet,
> > this means that the column is created with attnotnull set to true,
> > which tricks DefineIndex into thinking that the column already has a
> > NOT NULL constraint.
>
> Huh? The attnotnull bit *is* the constraint, there is no other
> representation. (There has been talk of making a pg_constraint
> entry but it isn't done today.)
>

Yes, I know. Sorry if my terminology was confusing. When I said
"constraint" I didn't mean a pg_constraint record, but the de facto
constraint created by ATExecSetNotNull -- it sets attnotnull to true
and checks that all of the values in the table are not null. It
doesn't do any of that if attnotnull has been set to true already,
which is how we arrive at the bug.

What we have here is a path where attnotnull can be set to true,
without the check ever occurring.

> I think the bug here is that ADD COLUMN NOT NULL has to fail if
> there's not a default expression supplied (except maybe we could
> allow it if the table contains no rows). ISTM we got this right
> in the past, wonder why it's not working now ...
>

No, ADD COLUMN NOT NULL is fine. It does fail if you don't supply a
default. This problem is particular to ADD COLUMN PRIMARY KEY.

Hmm, it's obvious that I didn't manage to convey my meaning in my
previous post. =/

Perhaps I should just post a patch; the changes to the code might
paint a clearer picture than my prose.

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

iD8DBQFIELml5YBsbHkuyV0RAg7xAKCYt9+BidrOKLthgN4SVdiEGApNsQCfa8T1
1D2DdttGCNMu1cXa4DZZnYQ=
=xkpm
-----END PGP SIGNATURE-----

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Emiliano Moscato 2008-04-24 16:56:27 Re: Stored procedures in C
Previous Message Scott Marlowe 2008-04-24 16:36:54 Re: How to modify ENUM datatypes?

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2008-04-24 16:57:43 Re: [GENERAL] I think this is a BUG?
Previous Message Bruce Momjian 2008-04-24 16:42:51 Re: Is this TODO item done?