jsonb unique constraints

From: Ted Toth <txtoth(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: jsonb unique constraints
Date: 2020-05-05 15:33:11
Message-ID: CAFPpqQGyQOrpXP4q1b-w=dcajKqf+mnC_mJ0HM3y-Gyo4yhSMA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Can you have unique constraints on jsonb columns keys? I've looked for
examples but haven't found any what is the proper syntax? Here's what I
tried:

CREATE TABLE report_json (
recnum int,
id integer,
report jsonb,
PRIMARY KEY (recnum),
CONSTRAINT report_json_unique_constraint UNIQUE (id,((report ->>
'data')::int),((report ->> 'ctc')::int),((report ->> 'dtg')::int)
);

which causes a syntax error at the first '(' around 'report ->>'.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2020-05-05 15:37:25 Re: Installing Postgis25_11
Previous Message Clifford Snow 2020-05-05 15:09:41 Re: Installing Postgis25_11