0
votes

how can I create a constraint using two fields. for example.

CREATE CONSTRAINT ON (m:BBG_Security_DATA) ASSERT m.ISIN, m.CUSIP IS UNIQUE;

When I am executing the above cypher statement it is giving an error message.

Thanks, Shafeeque

2
This question has been asked and answered many times before. For example, see question #2 of stackoverflow.com/questions/41862488/…, and the accepted answer.cybersam

2 Answers

1
votes

You can use triggers from APOC:

CREATE INDEX ON :BBG_Security_DATA (ISIN);

CREATE INDEX ON :BBG_Security_DATA (CUSIP);

CALL apoc.trigger.add(':BBG_Security_DATA (ISIN,CUSIP) IS UNIQUE', '
    UNWIND {createdNodes} AS n 
    WITH n 
         WHERE ALL(l in ["BBG_Security_DATA"] WHERE l in LABELS(n)) AND 
               ALL(k in ["ISIN", "CUSIP"] WHERE k in keys(n))
    MATCH (t:BBG_Security_DATA) 
          WHERE t<>n AND
                ALL(k in ["ISIN", "CUSIP"] WHERE t[k] = n[k])
    DETACH DELETE n
', {phase:'before'});
0
votes

This currently isn't supported by Neo4j. You may be able to code your own extension (likely using a TransactionEventHandler) to enforce this kind of behavior, though.