protectione055 commented on issue #2049: URL: https://github.com/apache/age/issues/2049#issuecomment-2295145936
I have discovered that the issue was due to my query missing the necessary JOIN key. After correcting the query, I was able to obtain the correct results. Below is the setup and the final working query: ``` SELECT * FROM ag_catalog.create_graph('my_graph'); -- vertex SELECT * FROM cypher('my_graph', $$ CREATE (a:Node {extid: 1, name: 'Node 1'}), (b:Node {extid: 2, name: 'Node 2'}), (c:Node {extid: 3, name: 'Node 3'}), (d:Node {extid: 4, name: 'Node 4'}), (e:Node {extid: 5, name: 'Node 5'}) $$) AS (result agtype); -- bidirectional edge SELECT * FROM cypher('my_graph', $$ MATCH (a:Node {extid: 1}), (b:Node {extid: 2}) CREATE (a)-[:CONNECTED_TO]->(b), (b)-[:CONNECTED_TO]->(a) $$) AS (result agtype); SELECT * FROM cypher('my_graph', $$ MATCH (b:Node {extid: 1}), (c:Node {extid: 3}) CREATE (b)-[:CONNECTED_TO]->(c), (c)-[:CONNECTED_TO]->(b) $$) AS (result agtype); SELECT * FROM cypher('my_graph', $$ MATCH (c:Node {extid: 2}), (d:Node {extid: 4}) CREATE (c)-[:CONNECTED_TO]->(d), (d)-[:CONNECTED_TO]->(c) $$) AS (result agtype); SELECT * FROM cypher('my_graph', $$ MATCH (d:Node {extid: 4}), (e:Node {extid: 5}) CREATE (d)-[:CONNECTED_TO]->(e), (e)-[:CONNECTED_TO]->(d) $$) AS (result agtype); -- bfs WITH RECURSIVE bfs AS ( SELECT id, extid, 1 AS level, ARRAY[id] AS visited FROM cypher('my_graph', $$ MATCH (n:Node {extid: 1}) RETURN id(n) AS id, n.extid AS extid $$) AS (id agtype, extid agtype) UNION ALL SELECT e.end_id AS id, e.end_extid AS extid, p.level + 1 AS level, p.visited || e.end_id AS visited FROM bfs AS p JOIN cypher('my_graph', $$ MATCH (n:Node)-[r:CONNECTED_TO]->(m:Node) RETURN id(n) AS start_id, id(m) AS end_id, m.extid AS end_extid $$) AS e(start_id agtype, end_id agtype, end_extid agtype) ON e.start_id = p.id WHERE e.end_id<>ANY(p.visited) ) SELECT * FROM bfs; ``` ``` id | extid | level | visited -----------------+-------+-------+--------------------------------------------------- 844424930131969 | 1 | 1 | {844424930131969} 844424930131970 | 2 | 2 | {844424930131969,844424930131970} 844424930131971 | 3 | 2 | {844424930131969,844424930131971} 844424930131973 | 5 | 2 | {844424930131969,844424930131973} 844424930131972 | 4 | 3 | {844424930131969,844424930131970,844424930131972} (5 rows) ``` -- 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-unsubscr...@age.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org