GET_DDL
GET_DDL(<table name>)
is a function that shows the CREATE TABLE statement for a table.
Tip
For views, see GET_VIEW_DDL.
For the entire database, see DUMP_DATABASE_DDL.
For UDFs, see GET_FUNCTION_DDL.
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 |
---|---|
|
The name of the schema. |
|
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';