Introduction
Easy way to Import & Export as CSV file in postgreSQL using psql copy command.
Query:
Import
COPY tablename From '/absolute _path_to_file/filename.csv' DELIMITERS '|' WITH NULL AS '';
Export
COPY tablename To '/absolute _path_to_file/filename.csv' DELIMITERS '|' WITH NULL AS '';
Constraints:
- User should be superuser i.e postgres.
- Path should be absolute and have full permission (chmod 777).
- Should be in local-machine where postgreSQL installed.
- While importing data from csv to DB, the field and data order should be same. (Say, If we have table with fields as ID & Name, then data in csv file should be 1 & Jayapal )
Labels: CSV, postgreSQL, psql
0 Comments:
Subscribe to:
Post Comments (Atom)