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

From David G. Johnston
Subject Re: unique index with several columns
Date
Msg-id CAKFQuwZuLqsmaFKHVbKry6v4tYHReVp_z6bgvr23vJXU1_OnRw@mail.gmail.com
Whole thread Raw
In response to unique index with several columns  ("Voillequin, Jean-Marc" <Jean-Marc.Voillequin@moodys.com>)
List pgsql-sql
The convention on these lists is to inline or bottom post.

On Fri, Mar 4, 2022 at 11:57 AM Klaus Kaisersberger <woodconsult@outlook.de> wrote:
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));


I'm not sure what your '{c1}' syntax means but I'll take it you are suggesting to construct an array.  This seems to fail quite easily if the values of c1 and c2 overlap.

David J.

pgsql-sql by date:

Previous
From: Klaus Kaisersberger
Date:
Subject: RE: unique index with several columns
Next
From: Klaus Kaisersberger
Date:
Subject: RE: unique index with several columns