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 17:59:47
Message-ID: 37ed240d0804241059x1a914898g87d1bfd4c6b34206@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 3:46 AM, Tom Lane 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
>

Yep, that's what I was trying to describe in my first post.

The ADD COLUMN code checks to see if the new column has been set to
is_not_null = true by transformColumnDefinition. That's at
parse_utilcmd.c:1738.

If it detects a NOT NULL column, it creates the new AT_SetNotNull
subcommand and adds it to the list, and sets the column's is_not_null
back to false.

> alter table t1 add column f2 int primary key;
>
> it produces an AT_AddColumn subcommand containing a ColumnDef with
> is_not_null = true, followed by an AT_AddIndex subcommand.
>

This is because transformIndexConstraint sets is_not_null = true for
any columns in a primary key constraint. That's at
parse_utilcmd.c:1127.

Note that this happens *after* transformAlterTableStmt performs the
check I mentioned above.

> This is not super consistent, and maybe should be cleaned up;
> but the intent is perfectly clear in both cases so I think tablecmds.c
> should be able to do the right thing with either.
>
> It looks to me that the appropriate fix involves doing
>
> tab->new_notnull |= colDef->is_not_null;
>
> somewhere in ATExecAddColumn; but I haven't tested this much.

Makes sense to me. I'll give it go.

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

iD8DBQFIEMqL5YBsbHkuyV0RAhjMAJ4lA0C9GQAcHFyFdom70OPgo+jzPQCg8eo2
ZVW9YjxpcvQVQmTSde5hApI=
=5Kzi
-----END PGP SIGNATURE-----

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2008-04-24 18:02:07 Re: How to modify ENUM datatypes?
Previous Message Oliver Helm 2008-04-24 17:52:39 Adding notes against fields

Browse pgsql-hackers by date

  From Date Subject
Next Message Steve Atkins 2008-04-24 18:01:13 Standard metadata queries
Previous Message Bruce Momjian 2008-04-24 17:49:19 Re: Proposed patch - psql wraps at window width