18.9 Python APIs for Executing UPDATE Queries
You can update a graph that is loaded into the graph server (PGX) using the Python APIs.
However, prior to updating the graph, you must first clone the graph. You can
perform update operations only on the cloned graph and not on the original
graph.
The following example shows the steps for running UPDATE queries against a
graph in the graph server (PGX) using the Python APIs.
Executing UPDATE Queries Against a PgxSession
You can also run UPDATE queries against a PgxSession
as shown:
>>> g1 = session.read_graph_by_name('BANK_GRAPH', 'pg_pgql')
>>> g2 = g1.clone(name="BANK_GRAPH_NEW")
>>> session.execute_pgql(
... "INSERT INTO BANK_GRAPH_NEW VERTEX v1 LABELS (Accounts) PROPERTIES (v1.id=1001, v1.name='New account-1') "
... ", VERTEX v2 LABELS (Accounts) PROPERTIES (v2.id=1002, v2.name='New account-2') "
... ", EDGE e1 BETWEEN v1 AND v2 LABELS (Transfers) PROPERTIES (e1.amount=3000) "
... )
>>> session.execute_pgql(
... "SELECT e.amount FROM MATCH (v1:Accounts) -[e:Transfers]-> (v2:Accounts) ON BANK_GRAPH_NEW "
... "WHERE v1.id=1001 AND v2.id=1002"
... ).print()
+--------+
| amount |
+--------+
| 3000.0 |
+--------+
Parent topic: Executing PGQL Queries Against the Graph Server (PGX)