PostgreSQL – Get definition of a materialized view

You can query the pg_matviews system catalog view to get ddl of a materialized view in Postgres database.

SELECT definition FROM pg_matviews WHERE schemaname='your_schema' AND matviewname='your_materialized_view';

See also  PostgreSQL - Empty a Table (Delete, Truncate)