15.8.1 Setting and Getting Property Values
Getting Property Values
You can obtain the vertex or edge property values by executing a SELECT
PGQL query on the graph.
For example:
Getting a Property Value Using JShell
opg4j> session.queryPgql("SELECT e.src_id, e.dest_id, e.amount FROM MATCH (n:Account) -[e:Transfers]-> (m:Account) on bank_graph").print();
Getting a Property Value Using Java
...
...
PgxGraph g = session.getGraph("bank_graph");
String query =
"SELECT e.src_id, e.dest_id, e.amount FROM MATCH (n:Account) -[e:Transfers]-> (m:Account)";
g.queryPgql(query).print();
The resulting property values may appear as:
+---------------------------+
| src_id | dest_id | amount |
+---------------------------+
| 1 | 259 | 1000 |
| 1 | 418 | 1000 |
| 1 | 584 | 1000 |
| 1 | 644 | 1000 |
| 1 | 672 | 1000 |
| 2 | 493 | 1000 |
| 2 | 546 | 1000 |
| 2 | 693 | 1000 |
| 2 | 833 | 1000 |
| 2 | 840 | 1000 |
+---------------------------+
Setting Property Values
You can set the vertex or edge property values by executing insert or update PGQL queries on the graph.
For example, to set a new vetex account ID on a graph using INSERT
query:
Setting a Property Value Using JShell
opg4j> PgxGraph g = session.getGraph("bank_graph_analytics");
g ==> PgxGraph[name=bank_graph_analytics,N=1000,E=5001,created=1616312153556]
opg4j> PgxGraph g_mutable = g.clone("bank_graph_analytics_copy");
g_mutable ==> PgxGraph[name=bank_graph_analytics_copy,N=1000,E=5001,created=1616312413799]
opg4j> g_mutable.executePgql("INSERT VERTEX v LABELS (Accounts) PROPERTIES ( v.id = 1001)");
Setting a Property Value Using Java
...
...
PgxGraph g1 = session.readGraphWithProperties("bank_graph_analytics.json");
PgxGraph g2 = g1.clone("bank_graph_analytics_copy");
g2.executePgql("INSERT VERTEX v " +
" LABELS ( Accounts ) " +
" PROPERTIES ( v.id = 1001 )");
Parent topic: Labels and Properties