-----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----- -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers