Am 24.03.24 um 16:41 schrieb Thiemo Kellner:
Am 24.03.2024 um 16:36 schrieb Andreas Kretschmer:
the null-able constraint addition to a column is pointless because by
default all columns are nullable. definition as a primary key adds
the not null constraint.
While this is certainly true, I do not see why the information that a
not null constraint is to be created or has been created is not
available.
postgres=# create table bla(i int null primary key);
CREATE TABLE
postgres=# \d bla
Table "public.bla"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
i | integer | | not null |
Indexes:
"bla_pkey" PRIMARY KEY, btree (i)
postgres=# drop table bla;
DROP TABLE
postgres=# create table bla(i int not null primary key);
CREATE TABLE
postgres=# \d bla
Table "public.bla"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
i | integer | | not null |
Indexes:
"bla_pkey" PRIMARY KEY, btree (i)
postgres=#
as you can see, there is no difference. the PK-Constraint is the
important thing here.
Andreas
--
Andreas Kretschmer
CYBERTEC PostgreSQL Services and Support