4

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.

1 Answer 1

8

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 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.