Reputation: 4808
As we can take a backup file of database using pg_dump command, similarly can we take backup of a select query result.
For example if i have a query select * from tablename;
then i want to take backup result of the query that can be restored somewhere.
Upvotes: 4
Views: 4656
Reputation: 51609
You can use something like
copy (select * from tablename) to 'path/to/file';
it will generate csv file with results very same manner as pg_dump
does (in fact in plain mode it actually runs COPY
commands)
update
and if you want DDL as well, you can
create table specname as select * from tablename
and then
pg_dump -s specname
Upvotes: 8