6.3 Expanding a Subgraph
You can expand an in-memory subgraph by loading graph data from a SQL property graph into memory, and merging it with the current subgraph.
The following applies when merging two subgraphs:
- Expanding a subgraph with data from another SQL graph is only possible if the graph schemas are compatible.
- The initial subgraph for expanding can also be loaded from a PGQL property graph and need not necessarily originate from a SQL property graph.
- You can only expand a subgraph by loading graph data from a property graph that exists in the current database schema.
- Also, see Dynamically Expanding a Subgraph for additional information.
The following example shows the expansion of the subgraph created in Loading a Subgraph Using PGQL Queries:
opg4j> graph = graph.expandGraph().
...> withPgql().
...> fromPgSql("STUDENT_NETWORK").
...> queryPgql("MATCH (v1 IS Person) WHERE id(v1) = 'PERSONS(4)'").
...> expand()
graph ==> PgxGraph[name=anonymous_graph_31,N=4,E=1,created=1681011908378]
PgxGraph graph = graph.expandGraph()
.withPgql()
.fromPgSql("STUDENT_NETWORK")
.queryPgql("MATCH (v1 IS Person) WHERE id(v1) = 'PERSONS(4)'")
.expand();
>>> graph = graph.expand_with_pgql("MATCH (v1 IS Person) WHERE id(v1) = 'PERSONS(4)'", pg_sql_name="STUDENT_NETWORK")
>>> graph
PgxGraph(name: anonymous_graph_34, v: 4, e: 1, directed: True, memory(Mb): 0)
Parent topic: Loading a SQL Property Graph into the Graph Server (PGX)