From: | Thiemo Kellner <thiemo(at)gelassene-pferde(dot)biz> |
---|---|
To: | "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Is this a buggy behavior? |
Date: | 2024-03-24 16:32:29 |
Message-ID: | 25bdf65d-7302-4e8d-bf9f-93752dbeec33@gelassene-pferde.biz |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Am 24.03.2024 um 17:15 schrieb Christophe Pettus:
> I think the point is that it's not really doing anything "silently." You are asking for a PRIMARY KEY constraint on a column, and it's giving it to you. One of the effects (not even really a side-effect) of that request is that the column is then declared NOT NULL.
But don't you also request the database to have the column being
nullable? So, PG, at this point silently prioritises the request for the
PK over the request of the nullability. Does it not?
>
> The reason it doesn't give you a warning is that by the time it would be in a position to, it's forgotten that you explicitly said NULL.
How can that be forgotten? This information ends up in the data
catalogue eventually!
> It does see that the column in nullable, but that in itself isn't worth emitting a warning over, since you are explicitly telling it that now the column shouldn't be null.
I would agree if you had two separate statements there, but in the
example it were not two different statements but one single
contradictory statement.
> It wouldn't make much more sense to emit a warning there than it would be in this situation:
>
> CREATE TABLE t (i int NULL);
> ALTER TABLE t ALTER i SET NOT NULL;
Again, these are two separate statements.
Maybe an example can help.
You are describing the situation when one goes to a car salesman and
orders a car painted in blue. The car gets manufactured and the salesman
hands you over the key. Then you say to the salesman. Now, please,
re-paint it in red.
The issue however arose, because the statement said. "Please order me a
blue car painted in red." Hopefully, any single salesman should respond
with something like. "Dear customer, all very well, but it contradictory
to have a blue car painted in red. Do you want a red car or a blue one?"
Dunkel war's, der Mond schien helle,
Als ein Wagen blitze schnelle,
langsam um die runde Ecke fuhr…
From | Date | Subject | |
---|---|---|---|
Next Message | Christophe Pettus | 2024-03-24 16:43:58 | Re: Is this a buggy behavior? |
Previous Message | Thiemo Kellner | 2024-03-24 16:15:58 | Re: Is this a buggy behavior? |