pg_dump --table=export_view --data-only --column-inserts mydb > export_view.sql
pg_dump (PostgreSQL) 10.7 (Ubuntu 10.7-1.pgdg18.04+1)
Export specific rows from a PostgreSQL table as INSERT SQL script and the postgresql documentation (https://www.postgresql.org/docs/10/app-pgdump.html) suggest it is possible to pg_dump
from a view with the --table
flag. If I export from the table directly I get the expected result (ie, data is exported). If I select from the view in psql I get the expected result. However whether I create a view or a materialized view and then try and pg_dump
, I get only the normal pg_dump
headers and no data. A commenter (https://stackoverflow.com/users/2036135/poshest) also appears to have faced the same issue in the above SO question, with no solution given.
If I CREATE TABLE blah AS SELECT x, y, z FROM MYTABLE
then I can export fine. If I CREATE VIEW blah AS SELECT x, y, z FROM MYTABLE
then the export is empty.
What am I doing wrong?
materialized view
s do actually store data, so if you're going for the pedagogical angle, you should probably include that restriction). There is absolutely no logical reason whypg_dump
couldn't include data from the result of calling a view though, and the documentation referenced fails to make this clear at all. – Interosculate