You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@age.apache.org by "WendelLana (via GitHub)" <gi...@apache.org> on 2023/08/23 11:38:34 UTC

[GitHub] [age] WendelLana commented on issue #1004: Research multi-label

WendelLana commented on issue #1004:
URL: https://github.com/apache/age/issues/1004#issuecomment-1689805762

   ### Multi-label queries supported in openCypher specification and Neo4j
   **Create a node with multiple labels**
   Query 1
   ```
   CREATE (n:Actor:Director)
   ```
   Query 2 - using SET
   ```
   CREATE (n)
   SET n:Actor:Director
   ```
   **Find all nodes which are defined with both labels of `Actor` and `Director`**
   Query 1 - filtering using WHERE
   ```
   MATCH (n) 
   WHERE n:Actor AND n:Director 
   RETURN n;
   ```
   Query 2 - filtering in the MATCH
   ```
   MATCH (n:Actor:Director)
   RETURN n;
   ```
   Query 3 - using label expression
   ```
   MATCH (n:Actor&Director)
   RETURN n;
   ```
   Query 4
   ```
   MATCH (n:Actor), (n:Director)
   RETURN n;
   ```
   **Find all nodes which have either label of `Actor` or `Director`**
   Query 1 - using `labels()` function
   ```
   MATCH (n)
   WHERE labels(n) IN [['Actor'],['Director'], ['Actor', 'Director']]
   RETURN n
   ```
   Query 2 - using WHERE
   ```
   MATCH (n)
   WHERE n:Actor OR n:Director
   RETURN n
   ```
   Query 3 - using UNION
   ```
   MATCH (n:Actor)
   RETURN n 
   
   UNION
   
   MATCH (n:Director) 
   RETURN n
   ```
   Query 4 - using COLLECT
   ```
   OPTIONAL MATCH (n1:Actor)
   WITH COLLECT(distinct n1) AS c1
   
   OPTIONAL MATCH (n2:Director) 
   WITH COLLECT(distinct n2) + c1 AS c2
   
   UNWIND c2 AS nodes
   RETURN nodes
   ```
   Query 5 - using label expression
   ```
   MATCH (n:Actor|Director)
   RETURN n
   ```
   **Remove labels `Actor` and `Director`**
   ```
   MATCH (n)
   REMOVE n:Actor:Director
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@age.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org