0

When in development, I need to clean down my system by restoring a database backup and then running SQL against it. Is there a way to do this:

restore schema dbo 'c:/data/mydatabase.backup';
update dbo."MyTable" set "ColumnA" = 1;

Unlike other questions, this is not for doing via the command line but in a query instead.

Postgres v9.5 with pgAdminIII.

2
  • 1
    No, there is no such SQL statement. The only way is to do it via command line (either with psql or pg_restore) Commented Nov 25, 2016 at 14:47
  • Thank you, would you care to make that an answer? So I can close off the question for anyone else landing here. Commented Nov 25, 2016 at 14:50

1 Answer 1

1

There is no support to restore a dump from within a SQL statement in Postgres.


Some possible (ugly) workarounds:

If your dump is a SQL script you could theoretically run that script from wherever you would run that (hypothetical) restore statement - but that would require parsing the script. And you would need to generate the dump using the --inserts option as otherwise the script contains psql specific statements.

Another workaround could be to create a stored function in a un-trusted language that is able to run operating system commands. The actual restore would still be done by the command line utility, but you could initiate that from within SQL.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the ugly workarounds. I'm going to go into Powershell instead!

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.