Store a PgxFrame in Database

You can store a PgxFrame output to relational database tables.

The outputs of the property graph machine learning algorithms are PgxFrame(s) and this data structure can be stored in the database. The columns and rows of the PgxFrame correspond to the columns and rows of the database table.

The following example converts a PGQL result set to a PgxFrame, which is then stored as a table to the database.

var g = session.readGraphByName("BANK_GRAPH", GraphSource.PG_VIEW)
var query = "SELECT s.acct_id FROM MATCH (s) LIMIT 10"
var rs = g.queryPgql(query)
if (rs != null) {
  rs.toFrame().write().db()
    .tablename("accounts") // name of the DB table
    .overwrite(true)
    .store();
}
g = session.read_graph_by_name("BANK_GRAPH", "pg_view")
query = "SELECT s.acct_id FROM MATCH (s)"
rs = g.execute_pgql(query)
if (rs != None):
    rs.to_frame().write().db().table_name("accounts").overwrite(True).store()

On executing the notebook paragraph, the PgxFrame data gets inserted in the appropriate database table. You can verify this by viewing and querying the database table using Database Actions. See SQL Page in Database Actions for more information on running SQL statements in Database Actions.

Also, note the following: