29.2. Copying the OLAP Data from Heap Tables to an Analytical Table (metastore.copy_table) #

You can use an SQL command to copy the OLAP data from heap tables to an analytical table.

Required privileges:

For more information about stored procedures and privileges, refer to Section 22.1.

Execute the following command:

  SELECT metastore.copy_table('table_name', SQL_command, 'path_to_JSON');

Where:

Postgres Pro AXE performs the following actions:

  1. Verifies input parameters and user privileges.

  2. Creates a temporary storage directory for the SQL command results.

  3. Executes the SQL command and creates Parquet files with its results.

  4. Ensures metadata compatibility between Parquet files and the analytical table: the number, order, names, and types of columns must match.

  5. Creates new entries in pga_snapshot and pga_data_file metadata tables.

  6. Copies Parquet files to the storage directory of the analytical table, to a new subdirectory with the snapshot ID as the name.

    If Parquet files are added to a partitioned analytical table, they are split into multiple files based on partition columns, and a directory tree is created for these files.

  7. Updates statistics in pga_table_stats, pga_table_column_stats, and pga_file_column_statistics metadata tables.

Example 29.2. Executing the metastore.copy_table stored procedure

  SELECT metastore.copy_table('my_metastore_table', $$select * from my_pgtable$$, 'folder/options.json');