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
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
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'});
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.