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