I have a materialized view I created in Postgresql. I was wondering is there a way to pg_dump the materialized view as if they were tables, so when I import them into another database it sees it as tables rather than a view created from other tables?
Postgresql – Export Materialized View from postgresql as a table
materialized-viewpostgresql
Related Question
- How to view the original script that built a materialized view and that was created by another user
- Postgresql – Postgres 9.5 Materialized View from a table with jsonb columns
- Postgresql – Does CREATE/REFRESH MATERIALIZED VIEW in PostgreSQL use the parallel planner
- Postgresql – Get base table from materialized view in postgresql
- Postgresql – Multiple concurrent “REFRESH MATERIALIZED VIEW”: how to manage
- Rebuild materialized view from massive base tables
- Sql-server – Materialized view in SQL Server
- What does Oracle impdp do when a name clashes with a materialized view or synonym
Best Answer
I don't think there is a single-step way to do this. Are you trying to do this with one MV, or with a whole database full of them?
To get the proper CREATE TABLE statement with all the column types, you could do this:
And then use
pg_dump -t dummy1 > mv1.sql
to get the CREATE TABLE statement.To get the data, you would do:
You would then have to stitch the two files together with a name change from 'dummy1' to 'mv1' in the first file, to get the definition and the data to be combined in one replayable file.