I wanted to retrieve all the vertices from two different graphs I've created (one is called family_tree
and the other is taxonomy_biology
) and used the following command to do so :
SELECT * FROM cypher ('family_tree' AND 'taxonomy_biology', $$
MATCH (v)
RETURN v
$$) as (vertex agtype);
But then, the terminal returns this error :
ERROR: invalid input syntax for type boolean: "family_tree"
LINE 1: SELECT * FROM cypher('family_tree' AND 'taxonomy_biology', $...
Guessing how ApacheAGE works, it is going to search all the available graphs and return true
if there is an available graph with the same name or false
if it doesn't. Yet, passing two graphs that do exist will cause an error.
By the way, typing the same query, but for each graph, returned this :
SELECT * FROM cypher('taxonomy_biology', $$
MATCH (v)
RETURN v
$$) as (VERTEX agtype);
vertex
-----------------------------------------------------------------------------------------
{"id": 844424930131969, "label": "Kingdom", "properties": {"name": "Animalia"}}::vertex
{"id": 1125899906842625, "label": "Phylum", "properties": {"name": "Cnidaria"}}::vertex
(2 rows)
SELECT * FROM cypher('family_tree', $$ MATCH (v)
RETURN v
$$) as (VERTEX agtype);
vertex
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{"id": 844424930131969, "label": "Person", "properties": {"name": "Louis", "titles": ["Emperor of the Carolingian Empire", "King of the Franks", "King of Aquitaine"], "year_born": 778, "year_died": 840}}::vertex
{"id": 844424930131970, "label": "Person", "properties": {"name": "Hildegard", "titles": ["Frankish queen consort"], "year_born": 754, "year_died": 783}}::vertex
{"id": 844424930131971, "label": "Person", "properties": {"name": "Charlemagne", "titles": ["Holy Roman Emperor", "King of the Franks", "King of the Lombards"], "year_born": 747, "year_died": 814}}::vertex
(3 rows)
So, how can I return vertices from both of these graphs in a single query?
The UNION clause should work just fine, and another alternative would be using a JOIN clause, just like an example in the Apache docs
In your case, the code should be something like this using UNION:
SELECT *
FROM cypher ('family_tree', $$
MATCH (v)
RETURN v
$$) as (vertex agtype)
UNION
SELECT *
FROM cypher ('taxonomy_biology', $$
MATCH (v)
RETURN v
$$) as (vertex agtype);