Re: Bug of ALTER TABLE DROP CONSTRAINT - Mailing list pgsql-hackers

From Nikhil Sontakke
Subject Re: Bug of ALTER TABLE DROP CONSTRAINT
Date
Msg-id a301bfd90904020524q25197c22o2e69a87cb0f1180@mail.gmail.com
Whole thread Raw
In response to Re: Bug of ALTER TABLE DROP CONSTRAINT  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: Bug of ALTER TABLE DROP CONSTRAINT  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers
Hi,
> Considering the following sequence:
>    create table t(a int primary key);
>    alter table t drop constraint t_pkey;
>    insert into t values(null);
>    ERROR:  null value in column "a" violates not-null constraint
>
> My question is, why "null" is not allowed to be inserted after primary key
> constraint has been dropped.

Making a column into the primary key forces the column to NOT NULL.
You'll need to DROP NOT NULL separately.

It's probably possible to beat on the code hard enough to fix this,

Yeah it will be a matter of finding the affected column entries and invoking the removal of the not null entry from their corresponding pg_attribute rows.


but I'm not really sure there's much point, since the situation is
rare and the workaround is easy.

Yeah and it is documented already. Although it is not obvious immediately that a not-null attribute gets tagged onto the involved columns separately for primary, unique-not-null types of constraints.
 
Regards,
Nikhils
--
http://www.enterprisedb.com

pgsql-hackers by date:

Previous
From: Hiroshi Inoue
Date:
Subject: Re: More message encoding woes
Next
From: Robert Haas
Date:
Subject: Re: Bug of ALTER TABLE DROP CONSTRAINT