This should solve the task:
create unique index idx on t ((
case
when c1 is null and c2 is null then null
when c1 is null and c2 is not null then '{c2}'
when c1 is not null and c2 is null then '{c1}'
else '{c1,c2}'
end));
-----Original Message-----
From: Tom Lane <tgl@sss.pgh.pa.us>
Sent: Friday, March 4, 2022 7:32 PM
To: Alexey M Boltenkov <padrebolt@yandex.ru>
Cc: Voillequin, Jean-Marc <Jean-Marc.Voillequin@moodys.com>; David G. Johnston <david.g.johnston@gmail.com>;
pgsql-sql@lists.postgresql.org
Subject: Re: unique index with several columns
Alexey M Boltenkov <padrebolt@yandex.ru> writes:
> You need the new v15 feature:
> NULLS [NOT] DISTINCT
That won't replicate the behavior shown by the OP though.
In particular, not the weird inconsistency for all-null rows.
regards, tom lane