英文:
Is there a way to set multiple values for the same property of a node in AGE?
问题
我有一个包含火车站的图,其中每个站点至少属于一条线路。我想让一些站点属于两条线路,但不确定如何做到。以下是我想要实现的示例:
SELECT *
FROM cypher('Train', $$
CREATE (:Station {name: 'Station 1', line: 'Line 1', 'Line 2'})
$$) as (n agtype);
但这不起作用,因为每个属性只接受一个变量。我该如何实现这一目标?
英文:
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?
答案1
得分: 1
使用列表来存储属性的多个值。
SELECT *
FROM cypher('Train', $$
CREATE (:Station {name: 'Station 1', line: ['Line 1', 'Line 2']})
$$) as (n agtype);
参考链接:数据类型在 AGE
英文:
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
答案2
得分: 0
- 使用地图:
SELECT *
FROM cypher('test_graph', $$
CREATE (:Station {name: 'Station 1', line: {line_1: 'available', line_2: 'unavailable'}})
$$) as (n agtype);
- 使用地图的列表:
SELECT *
FROM cypher('test_graph', $$
CREATE (:Station {name: 'Station 1', line: {available: [1, 2, 3, 6, 7], unavailable: [4, 5, 8]}})
$$) as (n agtype);
英文:
Depending on data type and database architecture other alternative approaches to Lists would be:
- Using Maps:
SELECT *
FROM cypher('test_graph', $$
CREATE (:Station {name: 'Station 1', line: {line_1: 'available', line_2: 'unavailable'})
$$) as (n agtype);
- 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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论