GET VIEW DDL

GET_VIEW_DDL is a function that shows the CREATE VIEW statement for a view.

Syntax

SELECT GET_VIEW_DDL(["<schema_name>".]"<view_name>")

Parameters

Parameter

Parameter Type

Description

schema_name

Identifier

The name of the schema

view_name

Identifier

The name of the view

Examples

CREATE VIEW
  angry_animals AS
SELECT
  *
FROM
  cool_animals
WHERE
  is_agressive = false;


SELECT
  GET_VIEW_DDL("angry_animals");

CREATE VIEW "public".angry_animals AS
  SELECT
     "cool_animals"."id" as "id",
     "cool_animals"."name" as "name",
     "cool_animals"."weight" as "weight",
     "cool_animals"."is_agressive" as "is_agressive"
   FROM
     "public".cool_animals as cool_animals
   WHERE
     "cool_animals"."is_agressive" = false;

Exporting view DDL to a file

COPY
  (
    SELECT
      GET_VIEW_DDL("angry_animals")
  ) TO
WRAPPER
  csv_fdw
OPTIONS
  (LOCATION = 's3://sqream-docs/cool_animals_ddl.csv');

Permissions

The role must have the CONNECT permission at the database level.