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

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: (view raw, whole thread or download thread mbox)
Lists: pgsql-generalpgsql-hackers
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.

Version: GnuPG v1.4.7 (GNU/Linux)


In response to

pgsql-hackers by date

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

pgsql-general by date

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

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