apache / age

Graph database optimized for fast analysis and real-time data processing. It is provided as an extension to PostgreSQL.
https://age.apache.org
Apache License 2.0
3.12k stars 412 forks source link

cypher returned agtype cannot work with postgres IN clause #1983

Closed wen-bing closed 3 months ago

wen-bing commented 3 months ago

Describe the bug cypher returned agtype cannot work with postgres IN clause

How are you accessing AGE (Command line, driver, etc.)? -PSQL

What data setup do we need to do?


1. create a graph and wtih a vertex label, like this(ignnore title and address fieldes)
select * from ag_catalog.cypher('graph1', $$
 Match (v:Person)
 return v
$$) as (v ag_catalog.agtype);
                                                                                 v
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
 {"id": 844424930131969, "label": "Person", "properties": {"name": "AAA", "title": "Developer", "address": [{"country": "China"}, {"province": "ANHUI"}]}}::vertex
 {"id": 844424930131970, "label": "Person", "properties": {"name": "BBB", "title": "Designer", "address": [{"country": "USA"}, {"province": "Beijing"}]}}::vertex
 {"id": 844424930131971, "label": "Person", "properties": {"name": "CCC", "title": "Tester", "address": [{"country": "Japan"}, {"province": "shanghai"}]}}::vertex
(3 rows)

2. create a table with data like this:
select * from table_person;
 name | age
------+-----
 AAA  |  12
 BBB  |  12
(2 rows)

3. use cypher under WITH clause

with graph_query as (
select * from ag_catalog.cypher('graph1', $$
 Match (v:Person)
 return v.name
$$) as (name ag_catalog.agtype)
)
select t.name,t.age from table_person as t where t.name in (select * from graph_query);

**ERROR:  operator does not exist: character varying = ag_catalog.agtype
LINE 7: ... t.name,t.age from table_person as t where t.name in (select...
                                                             ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.**
-------------------------------------query 2--------------------------------------------------------------
select t.name, t.age from table_person as t where
t.name in (
select * from ag_catalog.cypher('graph1', $$
Match(v:Person)
return v.name
$$) as (name ag_catalog.agtype));

**ERROR:  operator does not exist: character varying = ag_catalog.agtype
LINE 2: t.name in (
               ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.**

5.  use cypher under WITH clause ,after cast agtype to varchar, nothing returned.
with graph_query as (
select * from ag_catalog.cypher('graph1', $$
 Match (v:Person)
 return v.name
$$) as (name varchar(20))
)
select t.name,t.age from table_person as t where t.name in (select * from graph_query);

 name | age
------+-----
(0 rows)

Expected behavior cypher return value can be used in postgres WITH clause

Environment (please complete the following information):

wen-bing commented 3 months ago

casts agtype to *text works.

select t.name, t.age from table_person as t where t.name in ( select * from ag_catalog.cypher('graph1', $$ Match(v:Person) return v.name $$) as (name text));