create unique constraint on jsonb->filed during create table

From: Andy Fan <zhihui(dot)fan1213(at)gmail(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: create unique constraint on jsonb->filed during create table
Date: 2019-02-28 04:32:34
Message-ID: CAKU4AWpKK2FCWUXXwFsjnVhfta6mSWWFQ9_rteZ_c3Y3vTcEcg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

The following way works with 2 commands:

zhifan=# create table t1 (a jsonb);
CREATE TABLE
zhifan=# create unique index t1_a_name on t1 ((a->'name'));
CREATE INDEX

but know I want to merge them into 1 command, is it possible?

zhifan=# create table t2 (a jsonb, constraint uk_t2_a_name
unique((a->'name')));
ERROR: syntax error at or near "("
LINE 1: ...table t2 (a jsonb, constraint uk_t2_a_name unique((a->'name'...

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2019-02-28 04:47:58 Re: create unique constraint on jsonb->filed during create table
Previous Message Michael Paquier 2019-02-28 02:29:37 Re: cannot execute VACUUM during recovery