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…


Reply via email to