jccampagne opened a new issue, #1996: URL: https://github.com/apache/age/issues/1996
Is agtype like json? as suggested by the documentation (https://age.apache.org/age-manual/master/intro/types.html#data-types-an-introduction-to-agtype )? > AGE uses a custom data type called agtype, which is the only data type returned by AGE. Agtype is a superset of Json and a custom implementation of JsonB. That suggests that we can use PostgreSQL's json capabilities on the Cypher result. Using the documentation example ( https://age.apache.org/age-manual/master/functions/list_functions.html#data-setup ), we can do this: ``` SELECT a, b ->> 1 from cypher('graph_name', $$ MATCH (a) WHERE a.name = 'Alice' RETURN keys(a), keys(a) $$) as (a agtype, b agtype); a | ?column? -------------------------+---------- ["age", "eyes", "name"] | eyes ``` (using the `->>` operator as described here https://www.postgresql.org/docs/current/functions-json.html#FUNCTIONS-JSON-OP-TABLE ) However, trying to cast the result to json fails: ``` SELECT a, cast(b as json) from cypher('graph_name', $$ MATCH (a) WHERE a.name = 'Alice' RETURN ag_catalog.agtype_out(a), ag_catalog.agtype_out(a) $$) as (a agtype, b agtype); ``` errors with: ``` psql:sql/bug.sql:39: ERROR: cannot cast type agtype to json LINE 1: SELECT a, cast(b as json) from cypher('graph_name', $$ ``` Trying to return values as TEXT: ``` SELECT a, cast(b as json) from cypher('graph_name', $$ MATCH (a) WHERE a.name = 'Alice' RETURN ag_catalog.agtype_out(a), ag_catalog.agtype_out(a) $$) as (a text, b text); ``` will fail also: ``` psql:sql/bug.sql:39: ERROR: invalid input syntax for type json DETAIL: Expected end of input, but found ":". CONTEXT: JSON data, line 1: ...: {"age": 38, "eyes": "brown", "name": "Alice"}}:... ``` Using `to_json()` works, but does not do what we want (suggested here https://github.com/apache/age/issues/1225#issuecomment-1771498819 ): ``` SELECT a, to_json(b) from cypher('graph_name', $$ MATCH (a) WHERE a.name = 'Alice' RETURN ag_catalog.agtype_out(a), ag_catalog.agtype_out(a) $$) as (a text, b text); ``` results in: ``` a | to_json -----------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------- {"id": 844424930131969, "label": "Person", "properties": {"age": 38, "eyes": "brown", "name": "Alice"}}::vertex | "{\"id\": 844424930131969, \"label\": \"Person\", \"properties\": {\"age\": 38, \"eyes\": \"brown\", \"name\": \"Alice\"}}::vertex" (1 row) ``` It returns a string in JSON, not an object in JSON, moreover there's `::vertex` in the output value. This is what is causing the error when trying `cast(... as json)` This is related to this issue https://github.com/apache/age/issues/1225#issuecomment-2261489139 But that issue was closed already when I commented on it - not sure it's visible. -- 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.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org