You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@age.apache.org by GitBox <gi...@apache.org> on 2021/12/06 14:25:38 UTC

[GitHub] [incubator-age] joefagan commented on issue #152: How can i return the graph traversa as JSON using json_build_object?

joefagan commented on issue #152:
URL: https://github.com/apache/incubator-age/issues/152#issuecomment-986824887


   @afidegnum 
   No map and list are not reserved in SELECT ... as (map agtype)
   It returns a map or list only because the RETURN clause is shaped like 
   RETURN { , , } --returns map
   or
   RETURN [ , , ] --returns list
   
   Map and List can be replaced with foo or bar etc. It will rename the column output to foo or bar as shown in this complete example here.
   
   
   ```
   -- drop graph for cleanup between tests
   SELECT * FROM ag_catalog.drop_graph('test_graph', true);
   
   -- start from a new graph
   -- create parent connected to 2 children with multiple properties
   SELECT * FROM create_graph('test_graph');
   SELECT * FROM cypher('test_graph', $$
       CREATE (p:person {name: 'parent'})
       CREATE (c1:person {name: 'child1', age: 11 })
       CREATE (c2:person {name: 'child2', age: 12 })
       CREATE (p)-[:connect {type: 'is parent'}]->(c1)
       CREATE (p)-[:connect {type: 'is parent'}]->(c2)
       RETURN p
   $$) as (p agtype);
   
   SELECT * from cypher('test_graph', $$
             MATCH (p)-[R:connect]->(c)
             RETURN [p.name,R.type,c.name]
   $$) as (foo agtype);
   ```
   Last query returns
                   foo
   -----------------------------------
    ["parent", "is parent", "child2"]
    ["parent", "is parent", "child1"]
   


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