citusdata / cstore_fdw

Columnar storage extension for Postgres built as a foreign data wrapper. Check out https://github.com/citusdata/citus for a modernized columnar storage implementation built as a table access method.
Apache License 2.0
1.76k stars 171 forks source link

How to insert load / into cstore foreign tables in order #248

Open rameshkaranth opened 3 years ago

rameshkaranth commented 3 years ago

Hey team,

I read in the documentation of cstore_fdw that while loading data into cstore foreign table after sorting it on a column that is commonly used in the WHERE clause.

I am using a COPY from CSV to load the data in cstore foreign table like below

\COPY (SELECT * FROM tbl_metrics_partition_2020_q3 WHERE report_date >= '2020-09-01' AND report_date <= '2020-09-30') TO 'tbl_metrics_partition_fdw_2020_m9.csv' CSV DELIMITER ',' HEADER

\COPY tbl_metrics_partition_fdw_2020_m9 FROM 'tbl_metrics_partition_fdw_2020_m9.csv' CSV DELIMITER ',' HEADER
ljluestc commented 4 months ago
-- Create a CSV file with data sorted by a column commonly used in the WHERE clause
\COPY (
    SELECT * FROM tbl_metrics_partition_2020_q3 
    WHERE report_date >= '2020-09-01' AND report_date <= '2020-09-30'
    ORDER BY report_date -- Add ORDER BY clause here
) TO 'tbl_metrics_partition_fdw_2020_m9.csv' CSV DELIMITER ',' HEADER;

-- Copy the data from the CSV file into the cstore foreign table
\COPY tbl_metrics_partition_fdw_2020_m9 FROM 'tbl_metrics_partition_fdw_2020_m9.csv' CSV DELIMITER ',' HEADER;