Search code examples
agens-graph

How to create unique constraints on AgensGraph


I want to use "id" property as primary key on label.

agens=# create vlabel v;
CREATE VLABEL
agens=# create (:v{id:1});
GRAPH WRITE (INSERT VERTEX 1, INSERT EDGE 0)
agens=# create (:v{id:1});
GRAPH WRITE (INSERT VERTEX 1, INSERT EDGE 0)

But, I don't know grammar for create constraint.

How to create unique constraints on AgensGraph.


Solution

  • Use unique property index on AgensGraph.

    agens=# create (:v{id:1});
    GRAPH WRITE (INSERT VERTEX 1, INSERT EDGE 0)
    agens=# create unique property index on v(id);
    CREATE PROPERTY INDEX
    agens=# create (:v{id:1});
    ERROR:  duplicate key value violates unique constraint "v_id_idx"
    DETAIL:  Key ((properties.'id'::text))=(1) already exists.