patternsqlMinor
pg_restore a view
Viewed 0 times
pg_restoreviewstackoverflow
Problem
What's the best way to restore a view?
Is it possible to restore a view via pg_restore
pg_dump -h hostname -d databasename -Fc > db.dump
DROP VIEW viewname;
pg_restore -h hostname -d databasename -t viewname db.dumpThis does not error, but also doesn't seem to work. Have also tried it with the-nschema option. In verbose mode, it says pg_resore: implied data-only restore.
Is it possible to restore a view via pg_restore
Solution
In PostgreSQL 9.4 or older there does not appear to be a way to do this.
Here's the issue report I just posted.
If you want to patch pg_restore it looks pretty trivial, just add checking for under the test for
to
Here's the full patch: https://gist.github.com/ringerc/1743cfad34694fc9b9a3
You don't have to compile and install all of PostgreSQL for this, you can just compile a custom
update: Here's the -hackers post with the proposed patch.
update2: This is now fixed in 9.6 according to the docs
Here's the issue report I just posted.
If you want to patch pg_restore it looks pretty trivial, just add checking for under the test for
ropt->selTypes in _tocEntryRequired (in pg_backup_archiver.c), changing:strcmp(te->desc, "TABLE DATA") == 0)to
strcmp(te->desc, "TABLE DATA") == 0 ||
strcmp(te->desc, "VIEW") == 0)Here's the full patch: https://gist.github.com/ringerc/1743cfad34694fc9b9a3
You don't have to compile and install all of PostgreSQL for this, you can just compile a custom
pg_restore if you want.update: Here's the -hackers post with the proposed patch.
update2: This is now fixed in 9.6 according to the docs
Code Snippets
strcmp(te->desc, "TABLE DATA") == 0)strcmp(te->desc, "TABLE DATA") == 0 ||
strcmp(te->desc, "VIEW") == 0)Context
StackExchange Database Administrators Q#96729, answer score: 2
Revisions (0)
No revisions yet.