Re: Is this a buggy behavior?
От
Erik Wienhold
Тема
Re: Is this a buggy behavior?
Дата
Msg-id
yv3w7fykxqfqyio2mwentwipoojror5ebwhthpw4xfoiwaxikj@jri3ds4u7xfr
Ответ на
Список
Дерево обсуждения
Is this a buggy behavior? sud <suds1434@gmail.com>
Re: Is this a buggy behavior? Erik Wienhold <ewie@ewie.name>
Re: Is this a buggy behavior? Thiemo Kellner <thiemo@gelassene-pferde.biz>
Re: Is this a buggy behavior? Tom Lane <tgl@sss.pgh.pa.us>
Re: Is this a buggy behavior? sud <suds1434@gmail.com>
Re: Is this a buggy behavior? "Peter J. Holzer" <hjp-pgsql@hjp.at>
Re: Is this a buggy behavior? "David G. Johnston" <david.g.johnston@gmail.com>
Re: Is this a buggy behavior? "Peter J. Holzer" <hjp-pgsql@hjp.at>
Re: Is this a buggy behavior? Thiemo Kellner <thiemo@gelassene-pferde.biz>
Re: Is this a buggy behavior? Thiemo Kellner <thiemo@gelassene-pferde.biz>
Re: Is this a buggy behavior? Adrian Klaver <adrian.klaver@aklaver.com>
Re: Is this a buggy behavior? Christophe Pettus <xof@thebuild.com>
Re: Is this a buggy behavior? Thiemo Kellner <thiemo@gelassene-pferde.biz>
Re: Is this a buggy behavior? Laurenz Albe <laurenz.albe@cybertec.at>
Re: Is this a buggy behavior? Thiemo Kellner <thiemo@gelassene-pferde.biz>
Re: Is this a buggy behavior? Christophe Pettus <xof@thebuild.com>
Re: Is this a buggy behavior? Ron Johnson <ronljohnsonjr@gmail.com>
Re: Is this a buggy behavior? Christophe Pettus <xof@thebuild.com>
Re: Is this a buggy behavior? Thiemo Kellner <thiemo@gelassene-pferde.biz>
Re: Is this a buggy behavior? Andreas Kretschmer <andreas@a-kretschmer.de>
Re: Is this a buggy behavior? Thiemo Kellner <thiemo@gelassene-pferde.biz>
Re: Is this a buggy behavior? Andreas Kretschmer <andreas@a-kretschmer.de>
Re: Is this a buggy behavior? Thiemo Kellner <thiemo@gelassene-pferde.biz>
Re: Is this a buggy behavior? Erik Wienhold <ewie@ewie.name>
Re: Is this a buggy behavior? Erik Wienhold <ewie@ewie.name>
Re: Is this a buggy behavior? Thiemo Kellner <thiemo@gelassene-pferde.biz>
On 2024-03-24 15:25 +0100, sud wrote:
> Create a table and composite primary key. But to my surprise it allowed me
> to have the composite primary key created even if one of the columns was
> defined as nullable. But then inserting the NULL into that column erroring
> out at the first record itself , stating "not null constraint" is violated.
>
> CREATE TABLE test1
> (
> c1 varchar(36) NULL ,
> c2 varchar(36) NOT NULL ,
> CONSTRAINT test1_PK PRIMARY KEY (c1,c2)
> ) ;
>
> -- Table created without any error even one of the columns in the PK was
> defined as NULL.
>
> insert into test1 values(null,'123');
>
>
> *ERROR: null value in column "c1" of relation "test1" violates not-null
> constraintDETAIL: Failing row contains (null, 123).*
>
> insert into test1 values('123','123');
>
> --works fine as expected
This is required by the SQL standard: columns of a primary key must be
NOT NULL. Postgres automatically adds the missing NOT NULL constraints
when defining a primary key. You can verify that with \d test1 in psql.
Do you come from sqlite? That allows NULL in primary key columns
without an explicit NOT NULL constraint.
--
Erik
В списке pgsql-general по дате отправления