RE: unique index with several columns - Mailing list pgsql-sql

From Klaus Kaisersberger
Subject RE: unique index with several columns
Date
Msg-id PAXP193MB20580761317C5DE0F0444ACFE3059@PAXP193MB2058.EURP193.PROD.OUTLOOK.COM
Whole thread Raw
In response to Re: unique index with several columns  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses RE: unique index with several columns
List pgsql-sql
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



pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: unique index with several columns
Next
From: "David G. Johnston"
Date:
Subject: Re: unique index with several columns