tree-sitter-plpgsql/test/corpus/create/table.txt

373 lines
9.2 KiB
Plaintext

================================================================================
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: (number)
)
)
(column_definition
name: (identifier)
datatype: (keyword_timestamptz)
)
(column_definition
name: (identifier)
datatype: (varchar
(keyword_varchar)
size: (number)
)
)
(column_definition
name: (identifier)
datatype: (keyword_uuid)
)
)
)
)
)
================================================================================
Create a table with column constraints
================================================================================
create table foo (
id uuid primary key,
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_uuid)
(column_constraint
(keyword_primary)
(keyword_key)
)
)
(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
(literal_string)
)
)
)
)
)
)
)
================================================================================
Create a table with primary key and foreign key
================================================================================
create table foo (
id uuid primary key,
bar_id uuid null references bar (id) on update set null on delete cascade
);
--------------------------------------------------------------------------------
(source_file
(statement
(create_table
(keyword_create)
(keyword_table)
(table_reference
name: (identifier)
)
(column_definitions
(column_definition
name: (identifier)
datatype: (keyword_uuid)
(column_constraint
(keyword_primary)
(keyword_key)
)
)
(column_definition
name: (identifier)
datatype: (keyword_uuid)
(column_constraint
(keyword_null)
)
(column_constraint
(keyword_references)
(table_reference
name: (identifier)
)
refcolumn: (identifier)
(keyword_on)
(keyword_update)
(referencial_action
(keyword_set)
(keyword_null)
)
(keyword_on)
(keyword_delete)
(referencial_action
(keyword_cascade)
)
)
)
)
)
)
)
================================================================================
Create a table with named column constraints
================================================================================
create table foo (
id uuid constraint foo_pkey primary key,
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_uuid)
(column_constraint
(keyword_constraint)
name: (identifier)
(keyword_primary)
(keyword_key)
)
)
(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
(literal_string)
)
)
)
(column_definition
name: (identifier)
datatype: (keyword_text)
(column_constraint
(keyword_constraint)
name: (identifier)
(keyword_unique)
(keyword_nulls)
(keyword_not)
(keyword_distinct)
)
)
)
)
)
)