skip to Main Content

I have a graph with train stations, where each station belongs to at least one line. I would like to make several stations belong to 2 lines and am not sure how to do so. Here is an example of what I would like to achieve:

SELECT * 
FROM cypher('Train', $$
    CREATE (:Station {name: 'Station 1', line: 'Line 1', 'Line 2'})
$$) as (n agtype);

But this will not work as each property only takes one variable. How can I achieve this?

2

Answers


  1. Use list in order to store multiple values for a property.

    SELECT * 
    FROM cypher('Train', $$
    CREATE (:Station {name: 'Station 1', line: ['Line 1', 'Line 2']})
    $$) as (n agtype);
    

    Reference: Data types in AGE

    Login or Signup to reply.
  2. Depending on data type and database architecture other alternative approaches to Lists would be:

    1. Using Maps:
    SELECT *
    FROM cypher('test_graph', $$
        CREATE (:Station {name: 'Station 1', line: {line_1: 'available', line_2: 'unavailable'})
    $$) as (n agtype);
    
    1. Using Maps of Lists:
    SELECT *
    FROM cypher('test_graph', $$
        CREATE (:Station {name: 'Station 1', line: {available: [1, 2, 3, 6, 7], unavailable: [4, 5, 8]})
    $$) as (n agtype);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search