From: | "Peter J(dot) Holzer" <hjp-pgsql(at)hjp(dot)at> |
---|---|
To: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: Is this a buggy behavior? |
Date: | 2024-03-24 19:59:26 |
Message-ID: | 20240324195926.srwj5syrug3o6ygq@hjp.at |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 2024-03-24 11:23:22 -0700, David G. Johnston wrote:
> On Sun, Mar 24, 2024 at 11:14 AM Peter J. Holzer <hjp-pgsql(at)hjp(dot)at> wrote:
> It doesn't. Your statement
>
> > CREATE TABLE test1
> > (
> > c1 numeric NULL ,
> > c2 varchar(36) NOT NULL ,
> > CONSTRAINT test1_PK PRIMARY KEY (c1,c2)
> > ) ;
>
> creates the table with both columns being defined as NOT NULL:
>
>
>
> The request is a warning when defining a multi-column table constraint primary
> key if any of the columns comprising said PK are not defined already to be NOT
> NULL.
>
> Personally, green field at least, I find that to be reasonable.
Frankly, I don't. I see no reason why I should have declare a column
in a PK explicitely as NOT NULL.
Something like
CREATE TABLE test1
(
c1 numeric,
c2 varchar(36),
CONSTRAINT test1_PK PRIMARY KEY (c1,c2)
) ;
or
create table test2 (
id serial primary key,
...
);
should be totally fine. An explicit NOT NULL here is just noise and
doesn't add value.
I have some sympathy for the idea that an explicit NULL in a column
definition should cause a warning if the resulting column would not in
fact be nullable. But since writing NULL is otherwise exactly equivalent
to writing nothing, even that seems a bit inconsistent and might be
more confusing than helpful. In any case it seems like a very low-value
change to me which should only be done if it's very little effort
(which apparently it isn't).
hp
--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp(at)hjp(dot)at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
From | Date | Subject | |
---|---|---|---|
Next Message | Adrian Klaver | 2024-03-24 20:07:08 | Re: Empty materialized view |
Previous Message | Erik Wienhold | 2024-03-24 19:56:11 | Re: Empty materialized view |