News for hackers. Stuff that matters.
Re:Postgres 15 improves UNIQUE and NULL by masklinn on Monday July 11, 2022 @05:18AM (#32053896)
> But an employee can't be car-less twice!

What.

> That's what this change prohibits.

This change prohibits nothing, it allows specifying something (which was a bit complicated to enforce before).

Re:Postgres 15 improves UNIQUE and NULL by faho on Monday July 11, 2022 @05:26AM (#32053948)
>This change prohibits nothing, it allows specifying something (which was a bit complicated to enforce before).

It allows specifying a constraint - that you can't have two rows with the same values even if one of the values is a NULL. That's prohibiting duplicate NULLs. The change allows you to prohibit duplicate NULLs.

Say you have a table (EmployeeName, CarID). You could do a UNIQUE constraint on those two attributes, but that would still allow:

EmployeeName | CarID

Jeff | 2

Kim | NULL

Kim | NULL

Here, "Kim" is car-less (NULL in the CarID field) twice, which makes no sense.

Hence the new constraint.

Re:Postgres 15 improves UNIQUE and NULL by jhugo on Monday July 11, 2022 @05:58AM (#32054154)
Kim being car-less would be represented by Kim not appearing in this table at all. The design you've presented makes no sense.
Re:Postgres 15 improves UNIQUE and NULL by masklinn on Monday July 11, 2022 @05:57AM (#32054139)
> It allows specifying a constraint - that you can't have two rows with the same values even if one of the values is a NULL. That's prohibiting duplicate NULLs. The change allows you to prohibit duplicate NULLs.

Sure.

> Here, "Kim" is car-less (NULL in the CarID field) twice, which makes no sense.

The relation makes no sense to start with, it didn’t need duplicate nulls for that.

Re:Postgres 15 improves UNIQUE and NULL by jamesmstone on Monday July 11, 2022 @06:07AM (#32054204)
pre postgres 15 can you solve this with two unique constraints ?

unique (EmployeeName), unique (EmployeeName, CarID)

Re:Postgres 15 improves UNIQUE and NULL by masklinn on Monday July 11, 2022 @06:29AM (#32054342)
You’d most likely solve this by making the CarID NOT NULL because there’s why would you even have a row with no useful data?

And if this is your employee table, you’d have UNIQUE (EmployeeData) and UNIQUE (CarID), and it would do what you want.

Re:Postgres 15 improves UNIQUE and NULL by ryanbrunner on Monday July 11, 2022 @06:58AM (#32054505)
That's not quite the same, since the previous solution of unique (EmployeeName, CarID) allowed for one employee to have 2 separate cars. You have to use conditional indexes to solve this.