Database/GDB

Neo4j로 그래프db(gdb) 다루기: MERGE, 여러 속성 유니크 제약조건 (node key constraints

Tech Signal 2021. 8. 11. 17:17

영어원문: https://neo4j.com/docs/cypher-manual/current/clauses/merge/

 

이번엔 relationship(edge), 엣지를 그을 때의 MERGE 사용법을 다룬다. node(노드) 만들 때의 사용법은 바로 이전 글에.

 

CREATE CONSTRAINT ON (n:Person) ASSERT n.name IS UNIQUE;
CREATE CONSTRAINT ON (n:Person) ASSERT n.role IS UNIQUE;

이런식으로 노드의 property가 unique하도록 지정할 수 있다

 

+ 다만 2020년 기준(neo4j 2.0.1) 여러 프로퍼티에 uniqueness 제약을 걸 수 없다고 한다. Enterprise edition neo4j 3.3에서는 node key constraints를 사용해 여러 프로퍼티에 유니크 constraint를 걸수 있다.

 참고: https://neo4j.com/docs/cypher-manual/current/constraints/#administration-constraints-node-key

 

Constraints - Neo4j Cypher Manual

This section explains how to manage constraints used for ensuring data integrity.

neo4j.com

MERGE (n:User{name: "hail", height:"155"})<-[r:OWNER_OF]-(n1:Pet{name:"bbobbi"})

이렇게 유일한 property를 잘 서술해서 relationship edge를 만들 수도 있다.