GET_DDL

GET_DDL(<table name>) is a function that shows the CREATE TABLE statement for a table.

Tip

Permissions

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

Syntax

get_ddl_statement ::=
    SELECT GET_DDL('[schema_name.]table_name')
    ;

schema_name ::= identifier

table_name ::= identifier

Parameters

Parameter

Description

schema_name

The name of the schema.

table_name

The name of the table.

Examples

Getting the DDL for a table

The result of the GET_DDL function is a verbose version of the CREATE TABLE syntax, which may include additional information that was added by SQream DB. For example, a NULL constraint may be specified explicitly.

farm=> CREATE TABLE cool_animals (
   id INT NOT NULL,
   name text(30) NOT NULL,
   weight FLOAT,
   is_agressive BOOL DEFAULT false NOT NULL
);
executed

farm=> SELECT GET_DDL('cool_animals');
create table "public"."cool_animals" (
  "id" int not null,
  "name" text(30) not null,
  "weight" double null,
  "is_agressive" bool default false not null )
  ;

Exporting table DDL to a file

COPY (SELECT GET_DDL('cool_animals')) TO '/home/rhendricks/animals.ddl';