You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@age.apache.org by "dukeofhazardz (via GitHub)" <gi...@apache.org> on 2023/06/06 19:32:03 UTC
[GitHub] [age] dukeofhazardz commented on issue #970: how to add nodes and edges in RDB without a cypher query so that it will be same as cypher query
dukeofhazardz commented on issue #970:
URL: https://github.com/apache/age/issues/970#issuecomment-1579334775
In order for you to add nodes and edges in a Relational Database without a cypher query, you need to modify the tables that represents the graph's structure
eg:
`SELECT * FROM ag_label;` provides you with the table containing all your nodes, edges and relationships.
You can display the table of all the vertices in a particular graph by performing this query;
`SELECT * FROM demo._ag_label_vertex;`, where `demo` is my graph and `ag_label_vertex` contains the vertices in my `demo` graph
You should see something like this;
```
id | properties
------------------+------------------------------------------
281474976710657 | {"name": "Pete"}
281474976710659 | {"name": "Mike"}
2251799813685249 | {"city": "New York", "name": "Pete"}
2251799813685250 | {"city": "Toronto", "name": "Mike"}
2251799813685251 | {"city": "Vancouver", "name": "Clint"}
2251799813685252 | {"city": "Dallas", "name": "Jane"}
2251799813685253 | {"city": "San Francisco", "name": "Tom"}
2533274790395906 | {"city": "Houston", "name": "Hugh"}
(8 rows)
```
Now you can manually add nodes and edges to a graph without a cypher query by running the query;
`INSERT INTO demo._ag_label_vertex(id, properties) VALUES ('2533274790395907', '{"name": "Mark"}');`
If you run `SELECT * FROM demo._ag_label_vertex;` again, you notice that the `{"name": "Mark"}` has been added to the table.
```
id | properties
------------------+------------------------------------------
281474976710657 | {"name": "Pete"}
281474976710659 | {"name": "Mike"}
2533274790395907 | {"name": "Mark"}
2251799813685249 | {"city": "New York", "name": "Pete"}
2251799813685250 | {"city": "Toronto", "name": "Mike"}
2251799813685251 | {"city": "Vancouver", "name": "Clint"}
2251799813685252 | {"city": "Dallas", "name": "Jane"}
2251799813685253 | {"city": "San Francisco", "name": "Tom"}
2533274790395906 | {"city": "Houston", "name": "Hugh"}
(9 rows)
```
If you run the regular cypher query;
```
demo=# SELECT * FROM cypher('demo', $$
demo$# MATCH (u)
demo$# RETURN u
demo$# $$) as (u agtype);
u
-------------------------------------------------------------------------------------------------------------
{"id": 281474976710657, "label": "", "properties": {"name": "Pete"}}::vertex
{"id": 281474976710659, "label": "", "properties": {"name": "Mike"}}::vertex
{"id": 2533274790395907, "label": "employer", "properties": {"name": "Mark"}}::vertex
{"id": 2251799813685249, "label": "worker", "properties": {"city": "New York", "name": "Pete"}}::vertex
{"id": 2251799813685250, "label": "worker", "properties": {"city": "Toronto", "name": "Mike"}}::vertex
{"id": 2251799813685251, "label": "worker", "properties": {"city": "Vancouver", "name": "Clint"}}::vertex
{"id": 2251799813685252, "label": "worker", "properties": {"city": "Dallas", "name": "Jane"}}::vertex
{"id": 2251799813685253, "label": "worker", "properties": {"city": "San Francisco", "name": "Tom"}}::vertex
{"id": 2533274790395906, "label": "employer", "properties": {"city": "Houston", "name": "Hugh"}}::vertex
(9 rows)
```
You can still find `{"name": "Mark"}` in the output.
--
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-unsubscribe@age.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org