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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With