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:

  1. CREATE SCHEMA statements, except for the public schema

  2. CREATE TABLE statements, including foreign tables

  3. CREATE VIEW statements, in dependency order

  4. SELECT SAVE_QUERY(...) statements for saved queries

  5. CREATE FUNCTION statements 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.