-----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-----