GET_VIEW_DDL(<view name>) is a function that shows the CREATE VIEW statement for a view.
The role must have the
CONNECT permission at the database level.
get_view_ddl_statement ::= SELECT GET_VIEW_DDL('[schema_name.]view_name') ; schema_name ::= identifier view_name ::= identifier
The name of the schema.
The name of the view.
Getting the DDL for a view
The result of the
GET_VIEW_DDL function is a verbose version of the CREATE VIEW statement, which may include additional information that was added by SQream DB. For example, schemas and column names will be be specified explicitly.
farm=> CREATE VIEW angry_animals AS SELECT * FROM cool_animals WHERE is_agressive = false; executed farm=> 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 '/home/rhendricks/angry_animals.sql';