Export PostgreSQL query result to file

We can take a backup file of database using pg_dump command, similarly can we take backup of a select query result.

Syntax to Export PostgreSQL query result to file:

copy(select * from table_name) to 'path';

Examples:

1.Export emp table data to flat file

copy(select * from emp) to 'C:/P Files/emp_table.txt';

2. Export emp table data to csv file

copy(select * from emp) to 'C:/P Files/emp_table.csv';

3. 2. Export emp table data to xls file

copy(select * from emp) to ‘C:/P Files/emp_table.xls’;

Responses are currently closed, but you can trackback from your own site.

Comments are closed.

Powered by k2schools
%d bloggers like this: