rafsun42 commented on issue #722:
URL: https://github.com/apache/age/issues/722#issuecomment-1476902090

   @jrgemignani 
   I am trying to return a property as json in the following example. But it 
throws an 'unable to cast' error.
   
   I have this vertex:
   ```
   CREATE (m:Person
           {
                   name: 'Matt',
                   edu: [
                           {school:'NSU', cgpa: 4.4},
                           {school:'York', cgpa: 4.3}
                   ]
           }
   ) RETURN (m.edu)
   ```
   The following queries work (returning 'edu' as 'agtype'):
   ```
   test=# SELECT * FROM cypher('my_graph', $$ MATCH (m: Person) RETURN m.edu 
$$) as (a agtype);
                                    a                                 
   -------------------------------------------------------------------
    [{"cgpa": 4.4, "school": "NSU"}, {"cgpa": 4.3, "school": "York"}]
   (1 row)
   ```
   But, the the following does not work (returning 'edu' as 'json'):
   ```
   test=# SELECT * FROM cypher('my_graph', $$ MATCH (m: Person) RETURN m.edu 
$$) as (a json);
   ERROR:  cannot cast type agtype to json for column "a"
   LINE 1: SELECT * FROM cypher('my_graph', $$ MATCH (m: Person) RETURN m.e...
   ```
   I found an workaround. The following querying wraps the property into 
`agtype_out` to make it return as a json string. It can then be parsed into 
json using Posgres' json functions.
   ```
   SELECT * FROM cypher('my_g', $$ MATCH (m: Person) RETURN 
ag_catalog.agtype_out(m.edu) $$) as (a text);
   ```
   But, I think the failed query should work without the workaround. You 
mentioned that the functionality is already there, but sadly I cannot find it. 
I found `datum_to_agtype` but not vice versa. Is there a function 
'agtype_to_datum', perhaps named differently?


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to