292 lines
7.2 KiB
Text
292 lines
7.2 KiB
Text
================================================================================
|
|
Create an empty table
|
|
================================================================================
|
|
create table foo ();
|
|
--------------------------------------------------------------------------------
|
|
|
|
(source_file
|
|
(statement
|
|
(create_table
|
|
(keyword_create)
|
|
(keyword_table)
|
|
(table_reference
|
|
name: (identifier)
|
|
)
|
|
(column_definitions)
|
|
)
|
|
)
|
|
)
|
|
|
|
================================================================================
|
|
Create an empty table in specified schema
|
|
================================================================================
|
|
create table public.foo ();
|
|
--------------------------------------------------------------------------------
|
|
|
|
(source_file
|
|
(statement
|
|
(create_table
|
|
(keyword_create)
|
|
(keyword_table)
|
|
(table_reference
|
|
schema: (identifier)
|
|
name: (identifier)
|
|
)
|
|
(column_definitions)
|
|
)
|
|
)
|
|
)
|
|
|
|
================================================================================
|
|
Create an empty temporary table
|
|
================================================================================
|
|
create temporary table foo ();
|
|
create temp table foo ();
|
|
--------------------------------------------------------------------------------
|
|
|
|
(source_file
|
|
(statement
|
|
(create_table
|
|
(keyword_create)
|
|
(keyword_temporary)
|
|
(keyword_table)
|
|
(table_reference
|
|
name: (identifier)
|
|
)
|
|
(column_definitions)
|
|
)
|
|
)
|
|
(statement
|
|
(create_table
|
|
(keyword_create)
|
|
(keyword_temporary)
|
|
(keyword_table)
|
|
(table_reference
|
|
name: (identifier)
|
|
)
|
|
(column_definitions)
|
|
)
|
|
)
|
|
)
|
|
|
|
================================================================================
|
|
Create an empty unlogged table
|
|
================================================================================
|
|
create unlogged table foo ();
|
|
--------------------------------------------------------------------------------
|
|
|
|
(source_file
|
|
(statement
|
|
(create_table
|
|
(keyword_create)
|
|
(keyword_unlogged)
|
|
(keyword_table)
|
|
(table_reference
|
|
name: (identifier)
|
|
)
|
|
(column_definitions)
|
|
)
|
|
)
|
|
)
|
|
|
|
================================================================================
|
|
Create an empty table if not exists
|
|
================================================================================
|
|
create table if not exists foo ();
|
|
--------------------------------------------------------------------------------
|
|
|
|
(source_file
|
|
(statement
|
|
(create_table
|
|
(keyword_create)
|
|
(keyword_table)
|
|
(keyword_if)
|
|
(keyword_not)
|
|
(keyword_exists)
|
|
(table_reference
|
|
name: (identifier)
|
|
)
|
|
(column_definitions)
|
|
)
|
|
)
|
|
)
|
|
|
|
================================================================================
|
|
Create a table with different columns
|
|
================================================================================
|
|
create table foo (
|
|
c1 text,
|
|
c2 boolean,
|
|
c3 numeric(1),
|
|
c4 timestamp with time zone,
|
|
c5 varchar(120),
|
|
c6 uuid
|
|
);
|
|
--------------------------------------------------------------------------------
|
|
|
|
(source_file
|
|
(statement
|
|
(create_table
|
|
(keyword_create)
|
|
(keyword_table)
|
|
(table_reference
|
|
name: (identifier)
|
|
)
|
|
(column_definitions
|
|
(column_definition
|
|
name: (identifier)
|
|
datatype: (keyword_text)
|
|
)
|
|
(column_definition
|
|
name: (identifier)
|
|
datatype: (keyword_boolean)
|
|
)
|
|
(column_definition
|
|
name: (identifier)
|
|
datatype: (numeric
|
|
(keyword_numeric)
|
|
precision: (literal)
|
|
)
|
|
)
|
|
(column_definition
|
|
name: (identifier)
|
|
datatype: (keyword_timestamptz)
|
|
)
|
|
(column_definition
|
|
name: (identifier)
|
|
datatype: (varchar
|
|
(keyword_varchar)
|
|
size: (literal)
|
|
)
|
|
)
|
|
(column_definition
|
|
name: (identifier)
|
|
datatype: (keyword_uuid)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
================================================================================
|
|
Create a table with column constraints
|
|
================================================================================
|
|
create table foo (
|
|
c1 text not null,
|
|
c2 text null,
|
|
c3 text not null default 'hello'
|
|
);
|
|
--------------------------------------------------------------------------------
|
|
|
|
(source_file
|
|
(statement
|
|
(create_table
|
|
(keyword_create)
|
|
(keyword_table)
|
|
(table_reference
|
|
name: (identifier)
|
|
)
|
|
(column_definitions
|
|
(column_definition
|
|
name: (identifier)
|
|
datatype: (keyword_text)
|
|
(column_constraint
|
|
(keyword_not)
|
|
(keyword_null)
|
|
)
|
|
)
|
|
(column_definition
|
|
name: (identifier)
|
|
datatype: (keyword_text)
|
|
(column_constraint
|
|
(keyword_null)
|
|
)
|
|
)
|
|
(column_definition
|
|
name: (identifier)
|
|
datatype: (keyword_text)
|
|
(column_constraint
|
|
(keyword_not)
|
|
(keyword_null)
|
|
)
|
|
(column_constraint
|
|
(keyword_default)
|
|
(literal)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
================================================================================
|
|
Create a table with named column constraints
|
|
================================================================================
|
|
create table foo (
|
|
c1 text constraint strong_c1 not null,
|
|
c2 text constraint weak_c2 null,
|
|
c3 text constraint "c3 with power" not null constraint "c2 set default hello" default 'hello',
|
|
c4 text constraint "c4 unique" unique nulls not distinct
|
|
);
|
|
--------------------------------------------------------------------------------
|
|
|
|
(source_file
|
|
(statement
|
|
(create_table
|
|
(keyword_create)
|
|
(keyword_table)
|
|
(table_reference
|
|
name: (identifier)
|
|
)
|
|
(column_definitions
|
|
(column_definition
|
|
name: (identifier)
|
|
datatype: (keyword_text)
|
|
(column_constraint
|
|
(keyword_constraint)
|
|
name: (identifier)
|
|
(keyword_not)
|
|
(keyword_null)
|
|
)
|
|
)
|
|
(column_definition
|
|
name: (identifier)
|
|
datatype: (keyword_text)
|
|
(column_constraint
|
|
(keyword_constraint)
|
|
name: (identifier)
|
|
(keyword_null)
|
|
)
|
|
)
|
|
(column_definition
|
|
name: (identifier)
|
|
datatype: (keyword_text)
|
|
(column_constraint
|
|
(keyword_constraint)
|
|
name: (identifier)
|
|
(keyword_not)
|
|
(keyword_null)
|
|
)
|
|
(column_constraint
|
|
(keyword_constraint)
|
|
name: (identifier)
|
|
(keyword_default)
|
|
(literal)
|
|
)
|
|
)
|
|
(column_definition
|
|
name: (identifier)
|
|
datatype: (keyword_text)
|
|
(column_constraint
|
|
(keyword_constraint)
|
|
name: (identifier)
|
|
(keyword_unique)
|
|
(keyword_nulls)
|
|
(keyword_not)
|
|
(keyword_distinct)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|