DUMP_DATABASE_DDL
DUMP_DATABASE_DDL() is a function that shows the CREATE statements for database objects including views and tables.
Syntax
SELECT DUMP_DATABASE_DDL()
Output
DUMP_DATABASE_DDL returns a single column, ddl, and includes UDFs. The statements are returned in the following order:
CREATE SCHEMAstatements, except for thepublicschemaCREATE TABLEstatements, including foreign tablesCREATE VIEWstatements, in dependency orderSELECT SAVE_QUERY(...)statements for saved queriesCREATE FUNCTIONstatements for UDFs
Examples
SELECT
DUMP_DATABASE_DDL();
Exporting database DDL to a file
COPY
(
SELECT
DUMP_DATABASE_DDL()
) TO
WRAPPER
csv_fdw
OPTIONS
(LOCATION = 's3://sqream-docs/database.ddl');
Permissions
The role must have the CONNECT permission at the database level.