Re: not null constraints, again - Mailing list pgsql-hackers

From Tender Wang
Subject Re: not null constraints, again
Date
Msg-id CAHewXNnoacxOeRsuae_Ja7UKjnLgiO7ttc2OUHNssfgGawT9Hw@mail.gmail.com
Whole thread Raw
In response to Re: not null constraints, again  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: not null constraints, again
List pgsql-hackers
 Hi,

I found an inconsistent behavior in v17.4 and v18 after not-null constraints were committed.

create table t1(a int not null);
ALTER TABLE  t1 ADD CONSTRAINT d PRIMARY KEY(a), ALTER a DROP NOT NULL;

in v17.4, ALTER TABLE successes, but in v18, it reports below error:
ERROR:  primary key column "a" is not marked NOT NULL

But if I separate the 'ALTER TABLE' command, there are no errors.
postgres=# create table t1(a int not null);
CREATE TABLE
postgres=# ALTER TABLE  t1 ADD CONSTRAINT d PRIMARY KEY(a), ALTER a DROP NOT NULL;
ERROR:  primary key column "a" is not marked NOT NULL
postgres=# ALTER TABLE  t1  ALTER a DROP NOT NULL;
ALTER TABLE
postgres=# ALTER TABLE  t1 ADD CONSTRAINT d PRIMARY KEY(a);
ALTER TABLE

in v17.4, we first drop not null, but when run add primary key constraint, set_notnull command will be added in transformIndexConstraint().
But in v18, the adding of set_notnull command logic in transformIndexConstraint()  has been removed. And when call ATPrepAddPrimaryKey(),
the column has not-null constraint, so will not add not-null again.

Is the above error expected in v18?  If so, we had better add more words to the document. If it's not, we should fix it.

BTW, the document doesn't state the order in which the commands are executed when users specify more than one manipulation in a single ALTER TABLE command.
 


--
Thanks,
Tender Wang

pgsql-hackers by date:

Previous
From: Thomas Munro
Date:
Subject: Re: Changing shared_buffers without restart
Next
From: Álvaro Herrera
Date:
Subject: Re: not null constraints, again