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

From jian he
Subject Re: not null constraints, again
Date
Msg-id CACJufxFdxmPjhHeBLHZwFGWVp-qzqziUbuFbzO0GrxF_uFFxzA@mail.gmail.com
Whole thread Raw
In response to Re: not null constraints, again  (jian he <jian.universality@gmail.com>)
Responses Re: not null constraints, again
List pgsql-hackers
create table t2 (a int primary key  constraint foo not null no inherit);
primary key cannot coexist with not-null no inherit?
here t2, pg_dump/restore will fail.

create table t7 (a int generated by default as identity, constraint
foo not null a no inherit, b int);
create table t7 (a int generated by default as identity not null no
inherit, b int);
first fail, second not fail. pg_dump output is:

CREATE TABLE public.t7 (a integer NOT NULL NO INHERIT,b integer);
ALTER TABLE public.t7 ALTER COLUMN a ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME public.t7_a_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);
seems there is a consistency between column_constraint, table_constraint.
but in this case, the public.t7 dump is fine.

-------------------------------------------------------------------------------
+      By contrast, a <literal>NOT NULL</literal> constraint that was created
+      as <literal>NO INHERIT</literal> will be changed to a normal inheriting
+      one during attach.
Does this sentence don't have corresponding tests?
i think you mean something like:

drop table if exists idxpart,idxpart0,idxpart1 cascade;
create table idxpart (a int not null) partition by list (a);
create table idxpart0 (a int constraint foo not null no inherit);
alter table idxpart attach partition idxpart0 for values in (0,1,NULL);

---------------------------------------------------------------------------------
the pg_dump of
-------------
drop table if exists idxpart, idxpart0 cascade;
create table idxpart (a int) partition by range (a);
create table idxpart0 (a int not null);
alter table idxpart attach partition idxpart0 for values from (0) to (100);
alter table idxpart alter column a set not null;
-------------
is

CREATE TABLE public.idxpart (a integer NOT NULL)PARTITION BY RANGE (a);
CREATE TABLE public.idxpart0 (a integer NOT NULL);
ALTER TABLE ONLY public.idxpart ATTACH PARTITION public.idxpart0 FOR
VALUES FROM (0) TO (100);

After pu_dump, the attribute conislocal of constraint
idxpart0_a_not_null changes from true to false,
is this OK for attribute change after pg_dump in this case?



pgsql-hackers by date:

Previous
From: jian he
Date:
Subject: Re: not null constraints, again
Next
From: wenhui qiu
Date:
Subject: Re: Patch: Show queries of processes holding a lock