To export a table data from Postgres database to a CSV file, use the "COPY to" command. You can create a CSV file using MS-Excel or directly create a file from the command.
Syntax: COPY (SELECT * FROM table_name) to E'C:\Users\main\Documents\file.csv' csv
Example: COPY (SELECT * FROM productcategory) to E'C:\Users\dinesh\Documents\prodcat.csv' csv
To import data from a CSV file to Postgres table , use the "COPY from" command.
Syntax: COPY table_name FROM E'C:\Users\main\Documents\file.csv' WITH Delimiter ',' Null '' csv;
Example: COPY product_product FROM E'C:\Users\dinesh\Documents\product.csv' WITH Delimiter ',' Null '' csv;
Note: Use double backslash for the file path and E'' fr the path string. You can use any format but that I will cover later.
0 Comment(s)