26.13.3 Storing a PgxFrame to a CSV File

In order to write a PgxFrame to a CSV file, you first need to explicitly authorize access to the corresponding directories by defining a directory object pointing to the directory (on the graph server) where the file needs to be written.
CREATE OR REPLACE DIRECTORY graph_files AS '/tmp';
GRANT READ, WRITE ON DIRECTORY graph_files TO GRAPH_DEVELOPER;

Also, note the following:

  • The directory in the CREATE DIRECTORY statement must exist on the graph server (PGX).
  • The directory must be writable at the OS level by the graph server (PGX).

The preceding code grants the privileges on the directory to the GRAPH_DEVELOPER role. However, you can also grant permissions to an individual user:

GRANT WRITE ON DIRECTORY graph_files TO <graph_user>;

You can then save a PgxFrame to a CSV file as shown in the following example:

opg4j> rsFrame.write().overwrite(true).csv("/tmp/Transfers.csv")
rsFrame.write().overwrite(true).csv("/tmp/Transfers.csv");
>>> rs_frame.store("/tmp/Transfers.csv")