DESCRIBE

Describe the definition of a table, view, or sequence. Optionally, return the DDL that created the object.

DESCRIBE { table | view | sequence } [ { WITH DDL | ONLY DDL } ]

For information about generating DDL for a specific database, see Generating DDL.

Parameters

table | view | sequence
Name of a persistent table, temporary table, view, or sequence. You can specify these objects with or without the schema name.
WITH DDL
Return the complete DDL that created the object as well as the table definition. The table definition is equivalent to the output of the ybsql \d command.
ONLY DDL
Return the complete DDL that created the object but not the table definition.

Examples

For example, describe the team table:
premdb=# describe team;
                                                
------------------------------------------------
   Column  |         Type          | Modifiers 
 ----------+-----------------------+-----------
  teamid   | smallint              | 
  htid     | smallint              | 
  atid     | smallint              | 
  name     | character varying(30) | 
  nickname | character varying(20) | 
  city     | character varying(20) | 
  stadium  | character varying(50) | 
  capacity | integer               | 
  avg_att  | numeric(5,3)          | 
 
 Distribution: Replicated
 
(14 rows)
Describe the season table and return its DDL:
premdb=# describe season with ddl;
                                                   
---------------------------------------------------
               Table "public.season"
 -------------+-----------------------+-----------
    Column    |         Type          | Modifiers 
 -------------+-----------------------+-----------
  seasonid    | smallint              | 
  season_name | character(9)          | 
  numteams    | smallint              | 
  winners     | character varying(30) | 
 
 Distribution: Replicated
 
 -- SHOW DDL
 -- Name: season
 -- Schema: public
 -- ---------------------------------
 CREATE TABLE season (
     seasonid smallint,
     season_name character(9),
     numteams smallint,
     winners character varying(30)
 )
 DISTRIBUTE REPLICATE
 ;
(26 rows)
Return DDL only for the season table:
premdb=# describe season only ddl;
                                      
--------------------------------------
 -- SHOW DDL
 -- Name: season
 -- Schema: public
 -- ---------------------------------
 CREATE TABLE season (
     seasonid smallint,
     season_name character(9),
     numteams smallint,
     winners character varying(30)
 )
 DISTRIBUTE REPLICATE
 ;
(12 rows)
Return DDL only for a sequence. Note that the start number is guaranteed to be equal to or greater than the originally specified start number. (See also Generating Values with Sequences.)
premdb=# create sequence sequence1 start 100000;
CREATE SEQUENCE
premdb=# describe sequence1 only ddl;
                                                 
-------------------------------------------------
 -- SHOW DDL
 -- Name: sequence1
 -- Schema: public
 -- --------------------------------------------
 CREATE SEQUENCE sequence1 START WITH 100352;
(5 rows)