jrgemignani commented on issue #1225:
URL: https://github.com/apache/age/issues/1225#issuecomment-1771498819
@cho2hhun When one outputs something from the `cypher()` function one needs
to specify what type it is, as you already know.
For the case of `agtype`, it generally has to be the type `agtype`. This is
because PG doesn't know how to generally cast `agtype` to certain other types.
Especially, since `agtype` is a composite and can be many different types -
```
psql-15.4-5432-pgsql=# SELECT * FROM cypher('graph_name', $$ WITH [1,2,3] as
lst RETURN lst[1] $$) AS (result agtype);
result
--------
2
(1 row)
psql-15.4-5432-pgsql=# SELECT * FROM cypher('graph_name', $$ WITH [1,2,3] as
lst RETURN lst[1] $$) AS (result integer);
result
--------
2
(1 row)
psql-15.4-5432-pgsql=# SELECT * FROM cypher('graph_name', $$ WITH [1,2,3] as
lst RETURN lst $$) AS (result agtype);
result
-----------
[1, 2, 3]
(1 row)
psql-15.4-5432-pgsql=# SELECT * FROM cypher('graph_name', $$ WITH [1,2,3] as
lst RETURN lst $$) AS (result _int4);
result
---------
{1,2,3}
(1 row)
```
However, if inside the cypher command you convert `agtype` to something
else, say a `cstring`, then you can utilize PG's casts to generate something
else -
```
psql-15.4-5432-pgsql=# SELECT to_json(result) FROM cypher('graph_name', $$
WITH [1,2,3] as lst RETURN ag_catalog.agtype_out(lst) $$) AS (result text);
to_json
-------------
"[1, 2, 3]"
(1 row)
psql-15.4-5432-pgsql=# SELECT pg_typeof(to_json(result)) FROM
cypher('graph_name', $$ WITH [1,2,3] as lst RETURN ag_catalog.agtype_out(lst)
$$) AS (result text);
pg_typeof
-----------
json
(1 row)
psql-15.4-5432-pgsql=#
```
It would probably be a good idea for our team to add in some additional
casts to make this easier for others.
Hope this is helpful.
--
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]