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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.