有没有一种方法在 AGE 中为节点的相同属性设置多个值?

huangapple go评论59阅读模式
英文:

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

  1. 使用地图:
SELECT *
FROM cypher('test_graph', $$
    CREATE (:Station {name: 'Station 1', line: {line_1: 'available', line_2: 'unavailable'}})
$$) as (n agtype);
  1. 使用地图的列表:
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:

  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);

huangapple
  • 本文由 发表于 2023年4月7日 03:58:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/75953314.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定