I'm trying to set a unique constraint between two columns (name and a), one of type text, and one of type json. How do I structure this in Postgres 9.6.3?
An example row looks like:
{ name: 'someName',
a: {
b: {
c: 'some text'
}
}
}
What is the postgres command to create a table for this? Currently I have this, which gives a syntax error near (.
CREATE TABLE action ( id bigint NOT NULL, name text, a json, unique (name, payload::json#>>'{message, payload, content}') );
I've also tried
CREATE TABLE action (
id bigint NOT NULL,
name text,
a json
);
ALTER TABLE actions ADD CONSTRAINT actions_constraint UNIQUE (payload::json#>>'{b, c, d}', name);
which keeps giving me this error:
ERROR: syntax error at or near "::"
How can I create this constraint?