Is there a query to retrieve only the labels for nodes and edges from a graph in a database? I know a query to retrieve the data information for nodes and edges from a graph, but it retrieves all the information. I'm wondering if there is a query to retrieve only the label information for nodes and edges.
Asked
Active
Viewed 114 times
3 Answers
0
This command will show you all the labels for all graphs under your database:
SELECT * FROM ag_catalog.ag_label;

Marco Souza
- 296
- 7
0
If you want to retrieve only the labels with cypher, you can execute the following command:
-- showing the vertex labels only
SELECT * FROM cypher('graph_name', $$
MATCH (v)
RETURN label(v)
$$) AS (vertex_label agtype);
-- showing the edge labels only
SELECT * FROM cypher('graph_name', $$
MATCH ()-[e]-()
RETURN label(e)
$$) AS (edge_label agtype);
And you can also retrieve it like everyone stated here:
SELECT * FROM ag_catalog.ag_label;

Matheus Farias
- 716
- 1
- 10
0
Let's suppose we have a Vertex With a single label v
and properties name
. We can use the query
Select * from cypher('demo' ,$$ Match(v:p) Return v $$ ) as (vertex agtype);
to return all the labels and their properties e.g
vertex |
---|
{"id": 9288674321451649, "label": "p", "properties": {"name": "John"}}::vertex |
Now when we only need the labels we run the query:
Select * from cypher('demo' ,$$ Match(v:p) Return labels(v) $$ ) as (vertex agtype);
to get the following:
vertex |
---|
"p" |
And you can also do:
SELECT * FROM ag_catalog.ag_label;

Martijn Pieters
- 1,048,767
- 296
- 4,058
- 3,343

Muhammad Zahid
- 154
- 8