Fetch JSONB Value for UNIQUE Constraint - Mailing list pgsql-hackers

From David E. Wheeler
Subject Fetch JSONB Value for UNIQUE Constraint
Date
Msg-id 47E3DF5A-EF5E-4FA9-9477-08CCCC37023C@justatheory.com
Whole thread Raw
Responses Re: Fetch JSONB Value for UNIQUE Constraint  (Peter Geoghegan <pg@bowt.ie>)
List pgsql-hackers
Dear Hackers,

Should this work?
   CREATE TABLE things (       user_id  INTEGER NOT NULL,       document JSONB   NOT NULL,       UNIQUE (user_id,
document->>'name')  );   ERROR:  syntax error at or near "->>"   LINE 4:     UNIQUE (user_id, document->>’name') 

I tried adding parens, but that didn’t work, either:
   CREATE TABLE things (       user_id  INTEGER NOT NULL,       document JSONB   NOT NULL,       UNIQUE (user_id,
(document->>'name'))  );   ERROR:  syntax error at or near "("   LINE 4:         UNIQUE (user_id, (document->>'name')) 

It works fine to create a unique index, though:
   CREATE TABLE things (       user_id  INTEGER NOT NULL,       document JSONB   NOT NULL   );   CREATE UNIQUE INDEX ON
things(user_id,(document->>'name')); 

So it’s a fine workaround, but maybe there’s something missing from the parsing of the CREATE TABLE statement? This is
on9.6.1. 

Best,

David


pgsql-hackers by date:

Previous
From: Andrew Gierth
Date:
Subject: Re: Hash support for grouping sets
Next
From: Peter Geoghegan
Date:
Subject: Re: Fetch JSONB Value for UNIQUE Constraint