grammar: add base create table

This commit is contained in:
Dmitriy Pleshevskiy 2023-01-06 23:52:08 +03:00
parent 78fa02efd1
commit ccc76f983a
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
36 changed files with 1529 additions and 111677 deletions

1110
grammar.js

File diff suppressed because it is too large Load diff

View file

@ -8,8 +8,7 @@ set -xe
if [ ! -z $(git diff --cached --name-only | grep -e "^grammar.js$") ]
then
make build
# TODO: Enable when performance improves
# make build-wasm
make build-wasm
git add src bindings *.wasm
fi

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

95758
src/parser.c

File diff suppressed because it is too large Load diff

View file

@ -1,353 +0,0 @@
================================================================================
add column
================================================================================
alter table foo add bar text;
--------------------------------------------------------------------------------
(source_file
(alter_table_statement
(identifier)
(alter_table_change
(alter_table_action
(table_column_item
(identifier)
(identifier))))))
================================================================================
if exists
================================================================================
alter table if exists foo add bar text;
--------------------------------------------------------------------------------
(source_file
(alter_table_statement
(if_exists)
(identifier)
(alter_table_change
(alter_table_action
(table_column_item
(identifier)
(identifier))))))
================================================================================
add column if not exists
================================================================================
alter table foo add column if not exists bar text;
--------------------------------------------------------------------------------
(source_file
(alter_table_statement
(identifier)
(alter_table_change
(alter_table_action
(if_not_exists)
(table_column_item
(identifier)
(identifier))))))
================================================================================
drop column
================================================================================
alter table foo drop column bar;
--------------------------------------------------------------------------------
(source_file
(alter_table_statement
(identifier)
(alter_table_change
(alter_table_action
(identifier)))))
================================================================================
drop column cascade
================================================================================
alter table foo drop column bar cascade;
--------------------------------------------------------------------------------
(source_file
(alter_table_statement
(identifier)
(alter_table_change
(alter_table_action
(identifier)
(alter_table_fk_ref_action)))))
================================================================================
drop column restrict
================================================================================
alter table foo drop column bar restrict;
--------------------------------------------------------------------------------
(source_file
(alter_table_statement
(identifier)
(alter_table_change
(alter_table_action
(identifier)
(alter_table_fk_ref_action)))))
================================================================================
drop column if exists
================================================================================
alter table foo drop column if exists bar restrict;
--------------------------------------------------------------------------------
(source_file
(alter_table_statement
(identifier)
(alter_table_change
(alter_table_action
(if_exists)
(identifier)
(alter_table_fk_ref_action)))))
================================================================================
set column default
================================================================================
alter table foo alter bar set default 4;
--------------------------------------------------------------------------------
(source_file
(alter_table_statement
(identifier)
(alter_table_change
(alter_table_action
(identifier)
(alter_column_action
(number))))))
================================================================================
drop column default
================================================================================
alter table foo alter bar drop default;
--------------------------------------------------------------------------------
(source_file
(alter_table_statement
(identifier)
(alter_table_change
(alter_table_action
(identifier)
(alter_column_action)))))
================================================================================
alter column type
================================================================================
alter table foo alter bar type text;
--------------------------------------------------------------------------------
(source_file
(alter_table_statement
(identifier)
(alter_table_change
(alter_table_action
(identifier)
(alter_column_action
(alter_column_type
(identifier)))))))
================================================================================
alter column type(1)
================================================================================
alter table foo alter bar set data type text;
--------------------------------------------------------------------------------
(source_file
(alter_table_statement
(identifier)
(alter_table_change
(alter_table_action
(identifier)
(alter_column_action
(alter_column_type
(identifier)))))))
================================================================================
alter column type(2)
================================================================================
alter table foo alter column bar set data type timestamptz using created at time zone 'utc';
--------------------------------------------------------------------------------
(source_file
(alter_table_statement
(identifier)
(alter_table_change
(alter_table_action
(identifier)
(alter_column_action
(alter_column_type
(identifier)
(time_expression
(identifier)
(string))))))))
================================================================================
column set not null
================================================================================
alter table foo alter bar set not null;
--------------------------------------------------------------------------------
(source_file
(alter_table_statement
(identifier)
(alter_table_change
(alter_table_action
(identifier)
(alter_column_action)))))
================================================================================
column drop not null
================================================================================
alter table foo alter bar drop not null;
--------------------------------------------------------------------------------
(source_file
(alter_table_statement
(identifier)
(alter_table_change
(alter_table_action
(identifier)
(alter_column_action)))))
================================================================================
column add constraint
================================================================================
alter table foo add constraint u_bar unique(bar);
--------------------------------------------------------------------------------
(source_file
(alter_table_statement
(identifier)
(alter_table_change
(alter_table_action
(table_constraint
(identifier)
(table_constraint_ty
(identifier)))))))
================================================================================
column drop constraint
================================================================================
alter table foo drop constraint u_bar;
--------------------------------------------------------------------------------
(source_file
(alter_table_statement
(identifier)
(alter_table_change
(alter_table_action
(identifier)))))
================================================================================
column drop constraint cascade
================================================================================
alter table foo drop constraint u_bar cascade;
--------------------------------------------------------------------------------
(source_file
(alter_table_statement
(identifier)
(alter_table_change
(alter_table_action
(identifier)
(alter_table_fk_ref_action)))))
================================================================================
column drop constraint restrict
================================================================================
alter table foo drop constraint u_bar restrict;
--------------------------------------------------------------------------------
(source_file
(alter_table_statement
(identifier)
(alter_table_change
(alter_table_action
(identifier)
(alter_table_fk_ref_action)))))
================================================================================
column drop constraint if exists
================================================================================
alter table foo drop constraint if exists u_bar restrict;
--------------------------------------------------------------------------------
(source_file
(alter_table_statement
(identifier)
(alter_table_change
(alter_table_action
(if_exists)
(identifier)
(alter_table_fk_ref_action)))))
================================================================================
many changes in columns
================================================================================
alter table foo drop constraint foo, add unique(foo);
--------------------------------------------------------------------------------
(source_file
(alter_table_statement
(identifier)
(alter_table_change
(alter_table_action
(identifier))
(alter_table_action
(table_constraint
(table_constraint_ty
(identifier)))))))
================================================================================
rename column
================================================================================
alter table foo rename column foo to bar;
--------------------------------------------------------------------------------
(source_file
(alter_table_statement
(identifier)
(alter_table_change
(alter_table_rename_column
(identifier)
(identifier)))))
================================================================================
rename constraint
================================================================================
alter table foo rename constraint foo to foo.bar;
--------------------------------------------------------------------------------
(source_file
(alter_table_statement
(identifier)
(alter_table_change
(alter_table_rename_constraint
(identifier)
(identifier)))))
================================================================================
rename table
================================================================================
alter table foo rename to foo.bar;
--------------------------------------------------------------------------------
(source_file
(alter_table_statement
(identifier)
(alter_table_change
(alter_table_rename_table
(identifier)))))
================================================================================
change schema
================================================================================
alter table foo set schema bar;
--------------------------------------------------------------------------------
(source_file
(alter_table_statement
(identifier)
(alter_table_change
(alter_table_change_schema
(identifier)))))

View file

@ -0,0 +1,38 @@
================================================================================
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)
)
)
)

View file

@ -1,192 +0,0 @@
================================================================================
body block
================================================================================
CREATE FUNCTION FOO () RETURNS void AS $$ BEGIN END $$ LANGUAGE sql;
--------------------------------------------------------------------------------
(source_file
(create_function_statement
(function_signature
(identifier)
(function_parameters))
(function_return
(identifier))
(block
(dollar_quote)
(body)
(dollar_quote))
(identifier)))
================================================================================
or replace
================================================================================
CREATE OR REPLACE FUNCTION FOO () RETURNS void AS 'select' LANGUAGE sql;
--------------------------------------------------------------------------------
(source_file
(create_function_statement
(or_replace)
(function_signature
(identifier)
(function_parameters))
(function_return
(identifier))
(string)
(identifier)))
================================================================================
immutable
================================================================================
CREATE FUNCTION FOO () RETURNS void AS 'select' LANGUAGE sql IMMUTABLE;
--------------------------------------------------------------------------------
(source_file
(create_function_statement
(function_signature
(identifier)
(function_parameters))
(function_return
(identifier))
(string)
(identifier)
(function_volatility)))
================================================================================
stable
================================================================================
CREATE FUNCTION FOO () RETURNS void AS 'select' LANGUAGE sql STABLE;
--------------------------------------------------------------------------------
(source_file
(create_function_statement
(function_signature
(identifier)
(function_parameters))
(function_return
(identifier))
(string)
(identifier)
(function_volatility)))
================================================================================
volatile
================================================================================
CREATE FUNCTION FOO () RETURNS void AS 'select' LANGUAGE sql VOLATILE;
--------------------------------------------------------------------------------
(source_file
(create_function_statement
(function_signature
(identifier)
(function_parameters))
(function_return
(identifier))
(string)
(identifier)
(function_volatility)))
================================================================================
returns array
================================================================================
CREATE FUNCTION FOO () RETURNS text[] AS 'select' LANGUAGE sql;
--------------------------------------------------------------------------------
(source_file
(create_function_statement
(function_signature
(identifier)
(function_parameters))
(function_return
(identifier))
(string)
(identifier)))
================================================================================
returns setof
================================================================================
CREATE FUNCTION FOO () RETURNS SETOF text AS 'select' LANGUAGE sql;
--------------------------------------------------------------------------------
(source_file
(create_function_statement
(function_signature
(identifier)
(function_parameters))
(function_return
(return_setof
(identifier)))
(string)
(identifier)))
================================================================================
returns setof array
================================================================================
CREATE FUNCTION FOO () RETURNS SETOF text[] AS 'select' LANGUAGE sql;
--------------------------------------------------------------------------------
(source_file
(create_function_statement
(function_signature
(identifier)
(function_parameters))
(function_return
(return_setof
(identifier)))
(string)
(identifier)))
================================================================================
returns table
================================================================================
CREATE FUNCTION FOO () RETURNS TABLE(a text, b bigint) AS 'select' LANGUAGE sql;
--------------------------------------------------------------------------------
(source_file
(create_function_statement
(function_signature
(identifier)
(function_parameters))
(function_return
(return_table
(var_declaration
(identifier)
(identifier))
(var_declaration
(identifier)
(identifier))))
(string)
(identifier)))
================================================================================
security definer
================================================================================
CREATE FUNCTION FOO () RETURNS void AS 'select' LANGUAGE sql SECURITY definer;
--------------------------------------------------------------------------------
(source_file
(create_function_statement
(function_signature
(identifier)
(function_parameters))
(function_return
(identifier))
(string)
(identifier)
(function_run_as)))
================================================================================
security invoker
================================================================================
CREATE FUNCTION FOO () RETURNS void AS 'select' LANGUAGE sql SECURITY INVOKER;
--------------------------------------------------------------------------------
(source_file
(create_function_statement
(function_signature
(identifier)
(function_parameters))
(function_return
(identifier))
(string)
(identifier)
(function_run_as)))

View file

@ -1,98 +0,0 @@
================================================================================
empty
================================================================================
CREATE FUNCTION FOO () RETURNS void AS 'select' LANGUAGE sql;
--------------------------------------------------------------------------------
(source_file
(create_function_statement
(function_signature
(identifier)
(function_parameters))
(function_return
(identifier))
(string)
(identifier)))
================================================================================
with argument
================================================================================
CREATE FUNCTION FOO (_foo bar.baz) RETURNS void AS 'select' LANGUAGE sql;
--------------------------------------------------------------------------------
(source_file
(create_function_statement
(function_signature
(identifier)
(function_parameters
(var_declaration
(identifier)
(identifier))))
(function_return
(identifier))
(string)
(identifier)))
================================================================================
default value
================================================================================
CREATE FUNCTION FOO (_foo bar.baz default '42') RETURNS void AS 'select' LANGUAGE sql;
--------------------------------------------------------------------------------
(source_file
(create_function_statement
(function_signature
(identifier)
(function_parameters
(var_declaration
(identifier)
(identifier))
(string)))
(function_return
(identifier))
(string)
(identifier)))
================================================================================
with arguments
================================================================================
CREATE FUNCTION FOO (foo bar, foo bar) RETURNS void AS 'select' LANGUAGE sql;
--------------------------------------------------------------------------------
(source_file
(create_function_statement
(function_signature
(identifier)
(function_parameters
(var_declaration
(identifier)
(identifier))
(var_declaration
(identifier)
(identifier))))
(function_return
(identifier))
(string)
(identifier)))
================================================================================
arrays
================================================================================
CREATE FUNCTION FOO (foo bar[], foo bar[][]) RETURNS void AS 'select' LANGUAGE sql;
--------------------------------------------------------------------------------
(source_file
(create_function_statement
(function_signature
(identifier)
(function_parameters
(var_declaration
(identifier)
(identifier))
(var_declaration
(identifier)
(identifier))))
(function_return
(identifier))
(string)
(identifier)))

View file

@ -1,93 +0,0 @@
================================================================================
basic
================================================================================
create index ON foo.bar(col);
--------------------------------------------------------------------------------
(source_file
(create_index_statement
(identifier)
(index_col
(identifier))))
================================================================================
with columns
================================================================================
create index on foo.bar (
col ASC NULLS FIRST,
col DESC NULLS LAST,
col NULLS FIRST,
(upper(col)) DESC);
--------------------------------------------------------------------------------
(source_file
(create_index_statement
(identifier)
(index_col
(identifier)
(index_col_dir)
(index_col_nulls))
(index_col
(identifier)
(index_col_dir)
(index_col_nulls))
(index_col
(identifier)
(index_col_nulls))
(index_col
(function_call
(identifier)
(identifier))
(index_col_dir))))
================================================================================
full syntax
================================================================================
create unique index concurrently if not exists idx_name on foo.bar using gist (col, (upper(bar)));
--------------------------------------------------------------------------------
(source_file
(create_index_statement
(if_not_exists)
(identifier)
(identifier)
(index_using
(identifier))
(index_col
(identifier))
(index_col
(function_call
(identifier)
(identifier)))))
================================================================================
include
================================================================================
create index ON foo.bar(col) include (col1, col2);
--------------------------------------------------------------------------------
(source_file
(create_index_statement
(identifier)
(index_col
(identifier))
(index_includes
(identifier)
(identifier))))
================================================================================
partial
================================================================================
create index ON foo.bar(col) where col > 25;
--------------------------------------------------------------------------------
(source_file
(create_index_statement
(identifier)
(index_col
(identifier))
(where_filter
(op_expression
(identifier)
(comparison_op)
(number)))))

View file

@ -1,77 +0,0 @@
================================================================================
basic
================================================================================
create schema foo;
--------------------------------------------------------------------------------
(source_file
(create_schema_statement
(identifier)))
================================================================================
for user
================================================================================
create schema authorization joe;
--------------------------------------------------------------------------------
(source_file
(create_schema_statement
(schema_role
(identifier))))
================================================================================
for current_user
================================================================================
create schema authorization current_user;
--------------------------------------------------------------------------------
(source_file
(create_schema_statement
(schema_role)))
================================================================================
for session_user
================================================================================
create schema authorization session_user;
--------------------------------------------------------------------------------
(source_file
(create_schema_statement
(schema_role)))
================================================================================
with name, for user
================================================================================
create schema foo authorization joe;
--------------------------------------------------------------------------------
(source_file
(create_schema_statement
(identifier)
(schema_role
(identifier))))
================================================================================
if not exists
================================================================================
create schema if not exists foo authorization joe;
--------------------------------------------------------------------------------
(source_file
(create_schema_statement
(if_not_exists)
(identifier)
(schema_role
(identifier))))
================================================================================
if not exists with name
================================================================================
create schema if not exists authorization joe;
--------------------------------------------------------------------------------
(source_file
(create_schema_statement
(if_not_exists)
(schema_role
(identifier))))

View file

@ -1,234 +0,0 @@
================================================================================
basic
================================================================================
create sequence foo;
--------------------------------------------------------------------------------
(source_file
(create_sequence_statement
(identifier)))
================================================================================
if not exists
================================================================================
create sequence if not exists foo;
--------------------------------------------------------------------------------
(source_file
(create_sequence_statement
(if_not_exists)
(identifier)))
================================================================================
temp
================================================================================
create temp sequence foo;
--------------------------------------------------------------------------------
(source_file
(create_sequence_statement
(temporary)
(identifier)))
================================================================================
temporary
================================================================================
create temporary sequence foo;
--------------------------------------------------------------------------------
(source_file
(create_sequence_statement
(temporary)
(identifier)))
================================================================================
as
================================================================================
create sequence foo as smallint;
--------------------------------------------------------------------------------
(source_file
(create_sequence_statement
(identifier)
(as
(identifier))))
================================================================================
increment
================================================================================
create sequence foo increment 5;
--------------------------------------------------------------------------------
(source_file
(create_sequence_statement
(identifier)
(sequence_increment
(number))))
================================================================================
increment by
================================================================================
create sequence foo increment by 5;
--------------------------------------------------------------------------------
(source_file
(create_sequence_statement
(identifier)
(sequence_increment
(number))))
================================================================================
minvalue
================================================================================
create sequence foo minvalue 5;
--------------------------------------------------------------------------------
(source_file
(create_sequence_statement
(identifier)
(sequence_min
(number))))
================================================================================
no minvalue
================================================================================
create sequence foo no minvalue;
--------------------------------------------------------------------------------
(source_file
(create_sequence_statement
(identifier)
(sequence_min)))
================================================================================
max value
================================================================================
create sequence foo maxvalue 5;
--------------------------------------------------------------------------------
(source_file
(create_sequence_statement
(identifier)
(sequence_max
(number))))
================================================================================
no max value
================================================================================
create sequence foo no maxvalue;
--------------------------------------------------------------------------------
(source_file
(create_sequence_statement
(identifier)
(sequence_max)))
================================================================================
start
================================================================================
create sequence foo start 5;
--------------------------------------------------------------------------------
(source_file
(create_sequence_statement
(identifier)
(sequence_start
(number))))
================================================================================
start with
================================================================================
create sequence foo start with 5;
--------------------------------------------------------------------------------
(source_file
(create_sequence_statement
(identifier)
(sequence_start
(number))))
================================================================================
cache
================================================================================
create sequence foo cache 4;
--------------------------------------------------------------------------------
(source_file
(create_sequence_statement
(identifier)
(sequence_cache
(number))))
================================================================================
no cycle
================================================================================
create sequence foo no cycle;
--------------------------------------------------------------------------------
(source_file
(create_sequence_statement
(identifier)
(sequence_cycle)))
================================================================================
cycle
================================================================================
create sequence foo cycle;
--------------------------------------------------------------------------------
(source_file
(create_sequence_statement
(identifier)
(sequence_cycle)))
================================================================================
owned by
================================================================================
create sequence foo owned by foo.bar;
--------------------------------------------------------------------------------
(source_file
(create_sequence_statement
(identifier)
(sequence_owned
(identifier))))
================================================================================
owned by none
================================================================================
create sequence foo owned by none;
--------------------------------------------------------------------------------
(source_file
(create_sequence_statement
(identifier)
(sequence_owned)))
================================================================================
full syntax
================================================================================
create temp sequence if not exists foo
as bigint increment -5
minvalue 5 no maxvalue
start with 3 cache 2 no cycle
owned by none;
--------------------------------------------------------------------------------
(source_file
(create_sequence_statement
(temporary)
(if_not_exists)
(identifier)
(as
(identifier))
(sequence_increment
(number))
(sequence_min
(number))
(sequence_max)
(sequence_start
(number))
(sequence_cache
(number))
(sequence_cycle)
(sequence_owned)))

View file

@ -1,345 +0,0 @@
================================================================================
create an empty table
================================================================================
create table foo();
--------------------------------------------------------------------------------
(source_file
(create_table_statement
(identifier)
)
)
================================================================================
create temporary table
================================================================================
create temp table foo();
create temporary table foo();
--------------------------------------------------------------------------------
(source_file
(create_table_statement
(temporary)
(identifier)
)
(create_table_statement
(temporary)
(identifier)
)
)
================================================================================
create table if not exists
================================================================================
create table if not exists foo();
--------------------------------------------------------------------------------
(source_file
(create_table_statement
(if_not_exists)
(identifier)
)
)
================================================================================
create unlogged table
================================================================================
create unlogged table foo();
--------------------------------------------------------------------------------
(source_file
(create_table_statement
(unlogged)
(identifier)
)
)
================================================================================
create table with predefined types
================================================================================
create table foo(
col1 numeric,
col2 numeric(2),
col3 numeric(2, 4),
col4 varchar,
col5 varchar(255)
);
--------------------------------------------------------------------------------
(source_file
(create_table_statement
(identifier)
(create_table_item
(table_column_item
(identifier)
(predefined_type)
)
)
(create_table_item
(table_column_item
(identifier)
(predefined_type (precision (number)))
)
)
(create_table_item
(table_column_item
(identifier)
(predefined_type (precision (number) (number)))
)
)
(create_table_item
(table_column_item
(identifier)
(predefined_type)
)
)
(create_table_item
(table_column_item
(identifier)
(predefined_type (type_length (number)))
)
)
)
)
================================================================================
constraints with deferred
================================================================================
create table foo(
col1 text not null deferrable,
col2 bigint not null deferrable initially immediate,
col3 numeric(2, 4) null deferrable initially deferred
);
--------------------------------------------------------------------------------
(source_file
(create_table_statement
(identifier)
(create_table_item
(table_column_item
(identifier)
(identifier)
(column_constraint
(column_constraint_ty)
(constraint_when))))
(create_table_item
(table_column_item
(identifier)
(identifier)
(column_constraint
(column_constraint_ty)
(constraint_when))))
(create_table_item
(table_column_item
(identifier)
(predefined_type
(precision
(number)
(number)))
(column_constraint
(column_constraint_ty)
(constraint_when))))))
================================================================================
column constraints
================================================================================
create table foo(
col1 text not null primary key check( col1 > b),
col2 bigint null default 25 deferrable initially immediate constraint a_name unique,
col3 numeric(2, 4) null deferrable initially deferred,
col4 int references foo.baz
);
--------------------------------------------------------------------------------
(source_file
(create_table_statement
(identifier)
(create_table_item
(table_column_item
(identifier)
(identifier)
(column_constraint
(column_constraint_ty))
(column_constraint
(column_constraint_ty))
(column_constraint
(column_constraint_ty
(op_expression
(identifier)
(comparison_op)
(identifier))))))
(create_table_item
(table_column_item
(identifier)
(identifier)
(column_constraint
(column_constraint_ty))
(column_constraint
(column_constraint_ty
(number))
(constraint_when))
(column_constraint
(identifier)
(column_constraint_ty))))
(create_table_item
(table_column_item
(identifier)
(predefined_type
(precision
(number)
(number)))
(column_constraint
(column_constraint_ty)
(constraint_when))))
(create_table_item
(table_column_item
(identifier)
(identifier)
(column_constraint
(column_constraint_ty
(constraint_foreign_key
(identifier))))))))
================================================================================
column fk references
================================================================================
create table foo(
col int references foo.baz(col1, col2),
col int references foo.baz on delete set default,
col int references foo.baz on delete no action on update cascade,
col int references foo.baz on delete restrict on update set null
);
--------------------------------------------------------------------------------
(source_file
(create_table_statement
(identifier)
(create_table_item
(table_column_item
(identifier)
(identifier)
(column_constraint
(column_constraint_ty
(constraint_foreign_key
(identifier)
(identifier)
(identifier))))))
(create_table_item
(table_column_item
(identifier)
(identifier)
(column_constraint
(column_constraint_ty
(constraint_foreign_key
(identifier)
(fk_action
(fk_ref_action)))))))
(create_table_item
(table_column_item
(identifier)
(identifier)
(column_constraint
(column_constraint_ty
(constraint_foreign_key
(identifier)
(fk_action
(fk_ref_action))
(fk_action
(fk_ref_action)))))))
(create_table_item
(table_column_item
(identifier)
(identifier)
(column_constraint
(column_constraint_ty
(constraint_foreign_key
(identifier)
(fk_action
(fk_ref_action))
(fk_action
(fk_ref_action)))))))))
================================================================================
table constraints - check
================================================================================
create table foo(
constraint one check (column_a > 5),
check (column_b > 5)
);
--------------------------------------------------------------------------------
(source_file
(create_table_statement
(identifier)
(create_table_item
(table_constraint
(identifier)
(table_constraint_ty
(op_expression
(identifier)
(comparison_op)
(number)))))
(create_table_item
(table_constraint
(table_constraint_ty
(op_expression
(identifier)
(comparison_op)
(number)))))))
================================================================================
table constraints - unique
================================================================================
create table foo(
unique (column_a, column_b)
);
--------------------------------------------------------------------------------
(source_file
(create_table_statement
(identifier)
(create_table_item
(table_constraint
(table_constraint_ty
(identifier)
(identifier))))))
================================================================================
table constraints - pk
================================================================================
create table foo(
primary key (column_a, column_b)
);
--------------------------------------------------------------------------------
(source_file
(create_table_statement
(identifier)
(create_table_item
(table_constraint
(table_constraint_ty
(identifier)
(identifier))))))
================================================================================
table constraints - fk
================================================================================
create table foo(
foreign key (column_a, column_b) references foo(name, age, bar)
);
--------------------------------------------------------------------------------
(source_file
(create_table_statement
(identifier)
(create_table_item
(table_constraint
(table_constraint_ty
(identifier)
(identifier)
(constraint_foreign_key
(identifier)
(identifier)
(identifier)
(identifier)))))))

View file

@ -1,184 +0,0 @@
================================================================================
basic
================================================================================
create trigger tr before insert on mytable execute foo();
--------------------------------------------------------------------------------
(source_file
(create_trigger_statement
(identifier)
(trigger_when)
(trigger_event)
(identifier)
(trigger_exec
(function_call
(identifier)))))
================================================================================
constraint
================================================================================
create constraint trigger tr before insert on mytable execute foo();
--------------------------------------------------------------------------------
(source_file
(create_trigger_statement
(identifier)
(trigger_when)
(trigger_event)
(identifier)
(trigger_exec
(function_call
(identifier)))))
================================================================================
after
================================================================================
create trigger tr after insert on mytable execute foo();
--------------------------------------------------------------------------------
(source_file
(create_trigger_statement
(identifier)
(trigger_when)
(trigger_event)
(identifier)
(trigger_exec
(function_call
(identifier)))))
================================================================================
instead of
================================================================================
create trigger tr instead of insert on mytable execute foo();
--------------------------------------------------------------------------------
(source_file
(create_trigger_statement
(identifier)
(trigger_when)
(trigger_event)
(identifier)
(trigger_exec
(function_call
(identifier)))))
================================================================================
many when
================================================================================
create trigger tr before insert or update or delete or truncate on mytable execute foo();
--------------------------------------------------------------------------------
(source_file
(create_trigger_statement
(identifier)
(trigger_when)
(trigger_event)
(identifier)
(trigger_exec
(function_call
(identifier)))))
================================================================================
scope for statement
================================================================================
create trigger tr before insert on mytable for statement execute foo();
--------------------------------------------------------------------------------
(source_file
(create_trigger_statement
(identifier)
(trigger_when)
(trigger_event)
(identifier)
(trigger_scope)
(trigger_exec
(function_call
(identifier)))))
================================================================================
scope for each row
================================================================================
create trigger tr before insert on mytable for each row execute foo();
--------------------------------------------------------------------------------
(source_file
(create_trigger_statement
(identifier)
(trigger_when)
(trigger_event)
(identifier)
(trigger_scope)
(trigger_exec
(function_call
(identifier)))))
================================================================================
scope for each statement
================================================================================
create trigger tr before insert on mytable for each statement execute foo();
--------------------------------------------------------------------------------
(source_file
(create_trigger_statement
(identifier)
(trigger_when)
(trigger_event)
(identifier)
(trigger_scope)
(trigger_exec
(function_call
(identifier)))))
================================================================================
execute procedure
================================================================================
create trigger tr before insert on mytable execute procedure foo();
--------------------------------------------------------------------------------
(source_file
(create_trigger_statement
(identifier)
(trigger_when)
(trigger_event)
(identifier)
(trigger_exec
(function_call
(identifier)))))
================================================================================
execute function
================================================================================
create trigger tr before insert on mytable execute function foo();
--------------------------------------------------------------------------------
(source_file
(create_trigger_statement
(identifier)
(trigger_when)
(trigger_event)
(identifier)
(trigger_exec
(function_call
(identifier)))))
================================================================================
when
================================================================================
create constraint trigger a.tr before insert or delete on foo.mytable for each statement when (new.baz != old.baz) execute function foo();
--------------------------------------------------------------------------------
(source_file
(create_trigger_statement
(identifier)
(trigger_when)
(trigger_event)
(identifier)
(trigger_scope)
(trigger_cond
(op_expression
(identifier)
(comparison_op)
(identifier)))
(trigger_exec
(function_call
(identifier)))))

View file

@ -1,37 +0,0 @@
================================================================================
empty
================================================================================
create type foo;
--------------------------------------------------------------------------------
(source_file
(create_type_statement
(identifier)))
================================================================================
with fields
================================================================================
create type foo as ( one text, two bigint[] );
--------------------------------------------------------------------------------
(source_file
(create_type_statement
(identifier)
(var_declaration
(identifier)
(identifier))
(var_declaration
(identifier)
(identifier))))
================================================================================
enum
================================================================================
create type foo.bar as enum ('one', 'two');
--------------------------------------------------------------------------------
(source_file
(create_type_statement
(identifier)
(string)
(string)))

View file

@ -1,104 +0,0 @@
================================================================================
whole table
================================================================================
delete from tasks;
--------------------------------------------------------------------------------
(source_file
(delete_statement
(identifier)))
================================================================================
where
================================================================================
delete from tasks where status <> 'Musical';
--------------------------------------------------------------------------------
(source_file
(delete_statement
(identifier)
(where_filter
(op_expression
(identifier)
(comparison_op)
(string)))))
================================================================================
returning
================================================================================
DELETE FROM tasks WHERE status = 'DONE' RETURNING *;
--------------------------------------------------------------------------------
(source_file
(delete_statement
(identifier)
(where_filter
(op_expression
(identifier)
(comparison_op)
(string)))
(select_item
(star))))
================================================================================
delete using subselect
================================================================================
DELETE FROM foo a USING (select baz from bar) b WHERE a.b = b.b;
--------------------------------------------------------------------------------
(source_file
(delete_statement
(identifier)
(identifier)
(delete_using
(from_item
(from_select
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_table
(identifier)))))
(identifier))))
(where_filter
(op_expression
(identifier)
(comparison_op)
(identifier)))))
================================================================================
with cte
================================================================================
with foo as (select * from bar)
delete from baz;
--------------------------------------------------------------------------------
(source_file
(delete_statement
(with_query
(with_query_item
(identifier)
(select_statement
(select_item
(star))
(select_from
(from_item
(from_table
(identifier)))))))
(identifier)))
================================================================================
returning into
================================================================================
delete from foo
returning id into _backup_id;
--------------------------------------------------------------------------------
(source_file
(delete_statement
(identifier)
(select_item
(identifier))
(into
(identifier))))

View file

@ -1,102 +0,0 @@
================================================================================
basic
================================================================================
drop function foo(bigint, text);
--------------------------------------------------------------------------------
(source_file
(drop_function_statement
(drop_function_item
(identifier)
(identifier)
(identifier))))
================================================================================
many at once
================================================================================
drop function foo(bigint, text), foo(bigint);
--------------------------------------------------------------------------------
(source_file
(drop_function_statement
(drop_function_item
(identifier)
(identifier)
(identifier))
(drop_function_item
(identifier)
(identifier))))
================================================================================
without args
================================================================================
drop function foo;
--------------------------------------------------------------------------------
(source_file
(drop_function_statement
(drop_function_item
(identifier))))
================================================================================
with no args
================================================================================
drop function foo();
--------------------------------------------------------------------------------
(source_file
(drop_function_statement
(drop_function_item
(identifier))))
================================================================================
cascade
================================================================================
drop function foo(bigint) cascade;
--------------------------------------------------------------------------------
(source_file
(drop_function_statement
(drop_function_item
(identifier)
(identifier))))
================================================================================
restrict
================================================================================
drop function foo(bigint) restrict;
--------------------------------------------------------------------------------
(source_file
(drop_function_statement
(drop_function_item
(identifier)
(identifier))))
================================================================================
if exists
================================================================================
drop function if exists foo();
--------------------------------------------------------------------------------
(source_file
(drop_function_statement
(drop_function_item
(if_exists)
(identifier))))
================================================================================
with argnames
================================================================================
drop function if exists foo(bar text, bigint);
--------------------------------------------------------------------------------
(source_file
(drop_function_statement
(drop_function_item
(if_exists)
(identifier)
(var_declaration
(identifier)
(identifier))
(identifier))))

View file

@ -1,51 +0,0 @@
================================================================================
basic
================================================================================
drop type foo;
--------------------------------------------------------------------------------
(source_file
(drop_type_statement
(identifier)))
================================================================================
many at once
================================================================================
drop type foo, bar;
--------------------------------------------------------------------------------
(source_file
(drop_type_statement
(identifier)
(identifier)))
================================================================================
cascade
================================================================================
drop type foo cascade;
--------------------------------------------------------------------------------
(source_file
(drop_type_statement
(identifier)))
================================================================================
restrict
================================================================================
drop type foo restrict;
--------------------------------------------------------------------------------
(source_file
(drop_type_statement
(identifier)))
================================================================================
if exists
================================================================================
drop type if exists foo;
--------------------------------------------------------------------------------
(source_file
(drop_type_statement
(if_exists)
(identifier)))

View file

@ -1,214 +0,0 @@
================================================================================
basic
================================================================================
do $$ begin execute 'command'; end $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(execute_statement
(string)))
(dollar_quote))))
================================================================================
into
================================================================================
do $$ begin execute 'command' into var; end $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(execute_statement
(string)
(into
(identifier))))
(dollar_quote))))
================================================================================
into strict
================================================================================
do $$ begin execute 'command' into strict var; end $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(execute_statement
(string)
(into
(identifier))))
(dollar_quote))))
================================================================================
using
================================================================================
do $$ begin execute 'command' using 1, foo(bar); end $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(execute_statement
(string)
(execute_using
(number)
(function_call
(identifier)
(identifier)))))
(dollar_quote))))
================================================================================
function call
================================================================================
do $$ begin execute foo() into strict var using 1; end $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(execute_statement
(function_call
(identifier))
(into
(identifier))
(execute_using
(number))))
(dollar_quote))))
================================================================================
string concatenation
================================================================================
do $$ begin execute 'foo' || 'bar' into _date; end $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(execute_statement
(op_expression
(string)
(other_op)
(string))
(into
(identifier))))
(dollar_quote))))
================================================================================
simple nested dollar quote
================================================================================
do $$ begin
execute format(
$sql$
select %1$s,
select 2,
$sql$
, _tbl_name) using bar;
end $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(execute_statement
(function_call
(identifier)
(dollar_quote_string)
(identifier))
(execute_using
(identifier))))
(dollar_quote))))
================================================================================
execute format dollar quote
================================================================================
do $$ begin
execute format(
$sql$
update %1$s
set foo = $1, %2$I = $1
$sql$
, _tbl_name) using bar;
end $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(execute_statement
(function_call
(identifier)
(dollar_quote_string)
(identifier))
(execute_using
(identifier))))
(dollar_quote))))
================================================================================
complex
================================================================================
do $$ begin
EXECUTE FORMAT(
$sql$
UPDATE %2$s SET new_val = $1
FROM ( SELECT serial AS _serial, created FROM %1$s ) t1
$sql$
, _tbl_name) USING baz, bar;
end $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(execute_statement
(function_call
(identifier)
(dollar_quote_string)
(identifier))
(execute_using
(identifier)
(identifier))))
(dollar_quote))))
================================================================================
complex(1)
================================================================================
do $$ begin
EXECUTE FORMAT($sql$
foo
$sql$ , _tbl_name) USING bar.baz;
end $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(execute_statement
(function_call
(identifier)
(dollar_quote_string)
(identifier))
(execute_using
(identifier))))
(dollar_quote))))

View file

@ -1,177 +0,0 @@
================================================================================
basic
================================================================================
grant all on table foo to postgres;
--------------------------------------------------------------------------------
(source_file
(grant_statement
(grant_privileges)
(grant_targets
(identifier))
(grant_roles
(identifier))))
================================================================================
all privileges
================================================================================
GRANT ALL PRIVILEGES ON TABLE FOO.BAR TO POSTGRES;
--------------------------------------------------------------------------------
(source_file
(grant_statement
(grant_privileges)
(grant_targets
(identifier))
(grant_roles
(identifier))))
================================================================================
many users
================================================================================
grant all on table foo to my_user, group another_user, current_user, public, session_user;
--------------------------------------------------------------------------------
(source_file
(grant_statement
(grant_privileges)
(grant_targets
(identifier))
(grant_roles
(identifier)
(identifier))))
================================================================================
on schema
================================================================================
GRANT CREATE, USAGE ON SCHEMA esl, esl_archive TO mercures_ws;
--------------------------------------------------------------------------------
(source_file
(grant_statement
(grant_privileges
(identifier)
(identifier))
(grant_targets
(identifier)
(identifier))
(grant_roles
(identifier))))
================================================================================
all tables in schema
================================================================================
grant all on all tables in schema foo to my_user;
--------------------------------------------------------------------------------
(source_file
(grant_statement
(grant_privileges)
(grant_targets
(identifier))
(grant_roles
(identifier))))
================================================================================
many tables
================================================================================
grant all on table bar, baz to my_user;
--------------------------------------------------------------------------------
(source_file
(grant_statement
(grant_privileges)
(grant_targets
(identifier)
(identifier))
(grant_roles
(identifier))))
================================================================================
functions
================================================================================
grant all on all functions in schema foo to my_user;
--------------------------------------------------------------------------------
(source_file
(grant_statement
(grant_privileges)
(grant_targets
(identifier))
(grant_roles
(identifier))))
================================================================================
function
================================================================================
grant all on function bar(text), baz(_arg my.type) to my_user;
--------------------------------------------------------------------------------
(source_file
(grant_statement
(grant_privileges)
(grant_targets
(grant_function
(identifier)
(identifier))
(grant_function
(identifier)
(identifier)
(identifier)))
(grant_roles
(identifier))))
================================================================================
all sequences
================================================================================
grant all on all sequences in schema foo to my_user;
--------------------------------------------------------------------------------
(source_file
(grant_statement
(grant_privileges)
(grant_targets
(identifier))
(grant_roles
(identifier))))
================================================================================
many sequences
================================================================================
grant all on sequence bar, baz to my_user;
--------------------------------------------------------------------------------
(source_file
(grant_statement
(grant_privileges)
(grant_targets
(identifier)
(identifier))
(grant_roles
(identifier))))
================================================================================
many privileges
================================================================================
grant connect, create, delete, execute, insert, references, select, temporary, trigger, truncate, update, usage on table bar to my_user;
--------------------------------------------------------------------------------
(source_file
(grant_statement
(grant_privileges
(identifier)
(identifier)
(identifier)
(identifier)
(identifier)
(identifier)
(identifier)
(identifier)
(identifier)
(identifier)
(identifier)
(identifier))
(grant_targets
(identifier))
(grant_roles
(identifier))))

View file

@ -1,288 +0,0 @@
================================================================================
basic
================================================================================
insert into my_table values (1);
--------------------------------------------------------------------------------
(source_file
(insert_statement
(identifier)
(insert_items
(insert_values
(insert_item (number))
)
)
)
)
================================================================================
insert into table by specified columns
================================================================================
insert into my_table (name, email, display_name) values
('foo', 'bar@biz.baz', 'Foo bar');
--------------------------------------------------------------------------------
(source_file
(insert_statement
(identifier)
(columns
(identifier)
(identifier)
(identifier)
)
(insert_items
(insert_values
(insert_item (string))
(insert_item (string))
(insert_item (string))
)
)
)
)
================================================================================
insert into table by specified columns with many values
================================================================================
insert into my_table (name, email, display_name) values
('foo', 'bar@biz.baz', 'Foo bar'),
('foo', 'bar@biz.baz', 'Foo bar'),
('foo', 'bar@biz.baz', 'Foo bar');
--------------------------------------------------------------------------------
(source_file
(insert_statement
(identifier)
(columns
(identifier)
(identifier)
(identifier)
)
(insert_items
(insert_values
(insert_item (string))
(insert_item (string))
(insert_item (string))
)
(insert_values
(insert_item (string))
(insert_item (string))
(insert_item (string))
)
(insert_values
(insert_item (string))
(insert_item (string))
(insert_item (string))
)
)
)
)
================================================================================
insert into table with alias
================================================================================
insert into foo.my_table as alias values(1);
--------------------------------------------------------------------------------
(source_file
(insert_statement
(identifier)
(as (identifier))
(insert_items
(insert_values
(insert_item (number))
)
)
)
)
================================================================================
insert into default values
================================================================================
insert into foo.my_table default values;
--------------------------------------------------------------------------------
(source_file
(insert_statement
(identifier)
(insert_items)
)
)
================================================================================
insert into with many value items
================================================================================
insert into foo.my_table values (1, 2);
--------------------------------------------------------------------------------
(source_file
(insert_statement
(identifier)
(insert_items
(insert_values
(insert_item (number))
(insert_item (number))
)
)
)
)
================================================================================
insert into with different kind of value items
================================================================================
insert into foo.my_table values (1, DEFAULT, (select 1, 2));
--------------------------------------------------------------------------------
(source_file
(insert_statement
(identifier)
(insert_items
(insert_values
(insert_item (number))
(insert_item)
(insert_item
(select_statement
(select_item (number))
(select_item (number))
)
)
)
)
)
)
================================================================================
insert into from select
================================================================================
insert into foo.my_table select column1 from foo bar;
--------------------------------------------------------------------------------
(source_file
(insert_statement
(identifier)
(insert_items
(select_statement
(select_item (identifier))
(select_from
(from_item
(from_table
(identifier)
(identifier)
)
)
)
)
)
)
)
================================================================================
insert into a table with the select enclosed in parentheses
================================================================================
insert into foo.my_table (select column1 from foo bar);
--------------------------------------------------------------------------------
(source_file
(insert_statement
(identifier)
(insert_items
(select_statement
(select_item (identifier))
(select_from
(from_item
(from_table
(identifier)
(identifier)
)
)
)
)
)
)
)
================================================================================
insert into with returning clause
================================================================================
insert into foo values (1) returning *, 1;
--------------------------------------------------------------------------------
(source_file
(insert_statement
(identifier)
(insert_items
(insert_values
(insert_item (number))
)
)
(returning
(select_item (star))
(select_item (number))
)
)
)
================================================================================
insert into using with clause
================================================================================
with foo as (select * from bar)
insert into my_table values (1);
--------------------------------------------------------------------------------
(source_file
(insert_statement
(with_query
(with_query_item
(identifier)
(select_statement
(select_item (star))
(select_from
(from_item
(from_table
(identifier)
)
)
)
)
)
)
(identifier)
(insert_items
(insert_values
(insert_item (number))
)
)
)
)
================================================================================
insert into statement with returning into clause
================================================================================
insert into foo (bar, baz) select * from another
returning id into _var;
--------------------------------------------------------------------------------
(source_file
(insert_statement
(identifier)
(columns
(identifier)
(identifier)
)
(insert_items
(select_statement
(select_item (star))
(select_from
(from_item
(from_table
(identifier)
)
)
)
)
)
(returning
(select_item (identifier))
)
(into (identifier))
)
)

View file

@ -1,169 +0,0 @@
================================================================================
on constraint do nothing
================================================================================
insert into foo default values on conflict on constraint foo do nothing;
--------------------------------------------------------------------------------
(source_file
(insert_statement
(identifier)
(insert_items)
(insert_conflict
(conflict_target
(identifier)))))
================================================================================
on conflict column names
================================================================================
insert into foo default values on conflict (foo, bar) do nothing;
--------------------------------------------------------------------------------
(source_file
(insert_statement
(identifier)
(insert_items)
(insert_conflict
(conflict_target
(identifier)
(identifier)))))
================================================================================
on conflict value expressions
================================================================================
insert into foo default values on conflict (coalesce(one, two), bar) do nothing;
--------------------------------------------------------------------------------
(source_file
(insert_statement
(identifier)
(insert_items)
(insert_conflict
(conflict_target
(function_call
(identifier)
(identifier)
(identifier))
(identifier)))))
================================================================================
update with default
================================================================================
insert into foo default values on conflict (foo) do update set foo = default;
--------------------------------------------------------------------------------
(source_file
(insert_statement
(identifier)
(insert_items)
(insert_conflict
(conflict_target
(identifier))
(update_set
(identifier)
(update_value)))))
================================================================================
update with expression
================================================================================
insert into foo default values on conflict (foo) do update set foo = 1;
--------------------------------------------------------------------------------
(source_file
(insert_statement
(identifier)
(insert_items)
(insert_conflict
(conflict_target
(identifier))
(update_set
(identifier)
(update_value
(number))))))
================================================================================
update with expression(1)
================================================================================
insert into foo default values on conflict (foo) do update set (foo) = (1);
--------------------------------------------------------------------------------
(source_file
(insert_statement
(identifier)
(insert_items)
(insert_conflict
(conflict_target
(identifier))
(update_set
(identifier)
(update_value
(number))))))
================================================================================
update with expression(2)
================================================================================
insert into foo default values on conflict (foo) do update set (foo, bar) = (1, 2, default);
--------------------------------------------------------------------------------
(source_file
(insert_statement
(identifier)
(insert_items)
(insert_conflict
(conflict_target
(identifier))
(update_set
(identifier)
(identifier)
(update_value
(number))
(update_value
(number))
(update_value)))))
================================================================================
update with expression(3)
================================================================================
insert into foo default values on conflict (foo) do update set foo = 1, bar = default, baz = (select 1);
--------------------------------------------------------------------------------
(source_file
(insert_statement
(identifier)
(insert_items)
(insert_conflict
(conflict_target
(identifier))
(update_set
(identifier)
(update_value
(number)))
(update_set
(identifier)
(update_value))
(update_set
(identifier)
(update_value
(select_statement
(select_item
(number))))))))
================================================================================
update with expression(4)
================================================================================
insert into foo default values on conflict (foo) do update set (foo) = (1), bar = default;
--------------------------------------------------------------------------------
(source_file
(insert_statement
(identifier)
(insert_items)
(insert_conflict
(conflict_target
(identifier))
(update_set
(identifier)
(update_value
(number)))
(update_set
(identifier)
(update_value)))))

View file

@ -1,196 +0,0 @@
================================================================================
empty
================================================================================
DO $$ BEGIN END $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body)
(dollar_quote))))
================================================================================
empty(1)
================================================================================
DO $$ DECLARE BEGIN END $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(declarations)
(body)
(dollar_quote))))
================================================================================
many declare(s)
================================================================================
DO $$
DECLARE one text;
DECLARE
name foo%TYPE;
age bar%ROWTYPE;
BEGIN END
$$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(declarations
(var_definition
(var_declaration
(identifier)
(identifier))))
(declarations
(var_definition
(var_declaration
(identifier)
(identifier)))
(var_definition
(var_declaration
(identifier)
(identifier))))
(body)
(dollar_quote))))
================================================================================
declare variables
================================================================================
DO $$
DECLARE
name text;
age bigint;
BEGIN END
$$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(declarations
(var_definition
(var_declaration
(identifier)
(identifier)))
(var_definition
(var_declaration
(identifier)
(identifier))))
(body)
(dollar_quote))))
================================================================================
declare with assignment
================================================================================
DO $$
DECLARE
name text := 'hello';
age bigint:= (SELECT foo() + 1);
BEGIN END
$$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(declarations
(var_definition
(var_declaration
(identifier)
(identifier))
(string))
(var_definition
(var_declaration
(identifier)
(identifier))
(select_statement
(select_item
(op_expression
(function_call
(identifier))
(number))))))
(body)
(dollar_quote))))
================================================================================
perform
================================================================================
DO $$
BEGIN
PERFORM foo();
END
$$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(perform_statement
(select_item
(function_call
(identifier)))))
(dollar_quote))))
================================================================================
many statements
================================================================================
DO $$
BEGIN
SELECT 1;
foo.bar = lower(foo.baz);
foo.bar := lower(foo.baz);
RETURN 2;
END
$$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(select_statement
(select_item
(number)))
(assign_statement
(identifier)
(function_call
(identifier)
(identifier)))
(assign_statement
(identifier)
(function_call
(identifier)
(identifier)))
(return_statement
(number)))
(dollar_quote))))
================================================================================
function call with select
================================================================================
DO $$ BEGIN perform exists(select 1); END $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(perform_statement
(select_item
(function_call
(identifier)
(select_statement
(select_item
(number)))))))
(dollar_quote))))

View file

@ -1,123 +0,0 @@
================================================================================
integer
================================================================================
do $$ begin
for foo in 1..10 loop select 1; end loop;
end $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(for_statement
(identifier)
(number)
(number)
(select_statement
(select_item
(number)))))
(dollar_quote))))
================================================================================
integer by step
================================================================================
do $$ begin
for foo in 1..do_something() by 5 loop select 1; end loop;
end $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(for_statement
(identifier)
(number)
(function_call
(identifier))
(number)
(select_statement
(select_item
(number)))))
(dollar_quote))))
================================================================================
integer reverse
================================================================================
do $$ begin
for foo in reverse 10..1 by 5 loop select 1; end loop;
end $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(for_statement
(identifier)
(number)
(number)
(number)
(select_statement
(select_item
(number)))))
(dollar_quote))))
================================================================================
for over query
================================================================================
do $$ begin
for foo, var in select generate_series(1,10) loop select 1; end loop;
end $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(for_statement
(identifier)
(identifier)
(select_statement
(select_item
(function_call
(identifier)
(number)
(number))))
(select_statement
(select_item
(number)))))
(dollar_quote))))
================================================================================
for over execute
================================================================================
do $$ begin
for foo, var in execute format($sql$ select $1 from %1$s; $sql$, _foo) using bar loop select 1; end loop;
end $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(for_statement
(identifier)
(identifier)
(execute_statement
(function_call
(identifier)
(dollar_quote_string)
(identifier))
(execute_using
(identifier)))
(select_statement
(select_item
(number)))))
(dollar_quote))))

View file

@ -1,25 +0,0 @@
================================================================================
get diagnostics
================================================================================
DO $$
BEGIN
get current diagnostics foo = ROW_COUNT;
get diagnostics bar := ROW_COUNT;
END
$$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(get_diagnostics_statement
(assign_statement
(identifier)
(identifier)))
(get_diagnostics_statement
(assign_statement
(identifier)
(identifier))))
(dollar_quote))))

View file

@ -1,224 +0,0 @@
================================================================================
basic
================================================================================
do $$ begin
if true then select 1; end if;
end $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(if_statement
(true)
(select_statement
(select_item
(number)))))
(dollar_quote))))
================================================================================
many statements
================================================================================
do $$ begin
if true then select 1; select 2; end if;
end $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(if_statement
(true)
(select_statement
(select_item
(number)))
(select_statement
(select_item
(number)))))
(dollar_quote))))
================================================================================
if then else
================================================================================
do $$ begin
if var <> 5 then return 1; else return 2; end if;
end $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(if_statement
(op_expression
(identifier)
(comparison_op)
(number))
(return_statement
(number))
(return_statement
(number))))
(dollar_quote))))
================================================================================
if then else if
================================================================================
do $$ begin
if var > 5 then return 1; elsif var = 4 then return 2; end if;
end $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(if_statement
(op_expression
(identifier)
(comparison_op)
(number))
(return_statement
(number))
(op_expression
(identifier)
(comparison_op)
(number))
(return_statement
(number))))
(dollar_quote))))
================================================================================
elseif/elsif
================================================================================
do $$ begin
if var > 5 then return 1; elsif var = 4 then return 2; elseif var = 3 then return 3; else return 4; end if;
end $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(if_statement
(op_expression
(identifier)
(comparison_op)
(number))
(return_statement
(number))
(op_expression
(identifier)
(comparison_op)
(number))
(return_statement
(number))
(op_expression
(identifier)
(comparison_op)
(number))
(return_statement
(number))
(return_statement
(number))))
(dollar_quote))))
================================================================================
nested
================================================================================
do $$ begin
if true then return 1; else if var = 4 then return 2; end if; end if;
end $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(if_statement
(true)
(return_statement
(number))
(if_statement
(op_expression
(identifier)
(comparison_op)
(number))
(return_statement
(number)))))
(dollar_quote))))
================================================================================
if is not null
================================================================================
do $$ begin
if foo is not null then select 1; end if;
end $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(if_statement
(op_expression
(identifier)
(comparison_null))
(select_statement
(select_item
(number)))))
(dollar_quote))))
================================================================================
if is not distinct from
================================================================================
do $$ begin
if foo is not distinct from bar then select 1; end if;
end $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(if_statement
(op_expression
(identifier)
(comparison_kw)
(identifier))
(select_statement
(select_item
(number)))))
(dollar_quote))))
================================================================================
if is distinct from
================================================================================
do $$ begin
if foo is distinct from bar then select 1; end if;
end $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(if_statement
(op_expression
(identifier)
(comparison_kw)
(identifier))
(select_statement
(select_item
(number)))))
(dollar_quote))))

View file

@ -1,42 +0,0 @@
================================================================================
open for select
================================================================================
DO $$
BEGIN
OPEN curs for select 2;
END
$$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(open_cursor_statement
(identifier)
(select_statement
(select_item
(number)))))
(dollar_quote))))
================================================================================
open for execute
================================================================================
DO $$
BEGIN
open foo for execute('select 1');
END
$$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(open_cursor_statement
(identifier)
(execute_statement
(string))))
(dollar_quote))))

View file

@ -1,70 +0,0 @@
================================================================================
dummy
================================================================================
do $$ begin
raise;
end $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(raise_statement))
(dollar_quote))))
================================================================================
basic
================================================================================
do $$ begin
raise 'alarms';
end $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(raise_statement
(string)))
(dollar_quote))))
================================================================================
with level
================================================================================
do $$ begin
raise notice 'alarms';
end $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(raise_statement
(identifier)
(string)))
(dollar_quote))))
================================================================================
with level and args
================================================================================
do $$ begin
raise notice 'alarms %d', _foo, bar;
end $$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(raise_statement
(identifier)
(string)
(identifier)
(identifier)))
(dollar_quote))))

View file

@ -1,64 +0,0 @@
================================================================================
return
================================================================================
DO $$
BEGIN
RETURN 1;
END
$$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(return_statement
(number)))
(dollar_quote))))
================================================================================
return query
================================================================================
DO $$
BEGIN
RETURN QUERY select 1;
END
$$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(return_statement
(select_statement
(select_item
(number)))))
(dollar_quote))))
================================================================================
return query execute
================================================================================
DO $$
BEGIN
RETURN QUERY execute format($sql$ select %1$s, $1;$sql$, _foo) using bar;
END
$$;
--------------------------------------------------------------------------------
(source_file
(do_block
(block
(dollar_quote)
(body
(return_statement
(execute_statement
(function_call
(identifier)
(dollar_quote_string)
(identifier))
(execute_using
(identifier)))))
(dollar_quote))))

View file

@ -1,179 +0,0 @@
================================================================================
from table
================================================================================
SELECT name FROM products;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_table
(identifier))))))
================================================================================
from many tables
================================================================================
SELECT products.name, i.name FROM products, items i, bar as baz;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_item
(identifier))
(select_from
(from_item
(from_table
(identifier)))
(from_item
(from_table
(identifier)
(identifier)))
(from_item
(from_table
(identifier)
(identifier))))))
================================================================================
sub select
================================================================================
SELECT name FROM (select foo from bar) alias, (select baz from bar) as alias1;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_select
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_table
(identifier)))))
(identifier)))
(from_item
(from_select
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_table
(identifier)))))
(identifier))))))
================================================================================
from function call
================================================================================
select name from foo(bar, baz);
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_function
(function_call
(identifier)
(identifier)
(identifier)))))))
================================================================================
from function call with alias
================================================================================
select name from foo() bar;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_function
(function_call
(identifier))
(identifier))))))
================================================================================
from function call with alias(1)
================================================================================
select name from foo() as bar;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_function
(function_call
(identifier))
(identifier))))))
================================================================================
from function call with alias in params
================================================================================
select name from foo() bar(alias1, alias2);
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_function
(function_call
(identifier))
(identifier)
(identifier)
(identifier))))))
================================================================================
from function call with alias in params(1)
================================================================================
select name from foo() as bar(alias1, alias2);
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_function
(function_call
(identifier))
(identifier)
(identifier)
(identifier))))))
================================================================================
from function call with alias in params(2)
================================================================================
select name from foo() as (alias1, alias2);
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_function
(function_call
(identifier))
(identifier)
(identifier))))))

View file

@ -1,332 +0,0 @@
================================================================================
cross join
================================================================================
SELECT name FROM products cross join items;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_table
(identifier))
(join_item
(from_item
(from_table
(identifier))))))))
================================================================================
join on
================================================================================
SELECT name FROM products join items on products.name = items.name;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_table
(identifier))
(join_item
(join_type)
(from_item
(from_table
(identifier)))
(join_condition
(op_expression
(identifier)
(comparison_op)
(identifier))))))))
================================================================================
join using
================================================================================
select name from products join items using(foo);
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_table
(identifier))
(join_item
(join_type)
(from_item
(from_table
(identifier)))
(join_condition
(identifier)))))))
================================================================================
natural join
================================================================================
select name from products natural join items;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_table
(identifier))
(join_item
(join_type)
(from_item
(from_table
(identifier))))))))
================================================================================
inner join
================================================================================
select name from products inner join items on true;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_table
(identifier))
(join_item
(join_type)
(from_item
(from_table
(identifier)))
(join_condition
(true)))))))
================================================================================
left join
================================================================================
select name from products left join items on true;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_table
(identifier))
(join_item
(join_type)
(from_item
(from_table
(identifier)))
(join_condition
(true)))))))
================================================================================
right join
================================================================================
select name from products right join items on true;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_table
(identifier))
(join_item
(join_type)
(from_item
(from_table
(identifier)))
(join_condition
(true)))))))
================================================================================
full join
================================================================================
select name from products full join items on true;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_table
(identifier))
(join_item
(join_type)
(from_item
(from_table
(identifier)))
(join_condition
(true)))))))
================================================================================
left outer join
================================================================================
select name from products left outer join items on true;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_table
(identifier))
(join_item
(join_type)
(from_item
(from_table
(identifier)))
(join_condition
(true)))))))
================================================================================
right outer join
================================================================================
select name from products right outer join items on true;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_table
(identifier))
(join_item
(join_type)
(from_item
(from_table
(identifier)))
(join_condition
(true)))))))
================================================================================
full outer join
================================================================================
select name from products full outer join items on true;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_table
(identifier))
(join_item
(join_type)
(from_item
(from_table
(identifier)))
(join_condition
(true)))))))
================================================================================
many joins
================================================================================
select name from products
natural join a
cross join a
join a on a.foo=b.foo
inner join a using(foo)
left join a using(foo)
left outer join a using(foo)
right join a using(foo)
right outer join a using(foo)
full outer join a using(foo)
full join a using(foo);
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_table
(identifier))
(join_item
(join_type)
(from_item
(from_table
(identifier))))
(join_item
(from_item
(from_table
(identifier))))
(join_item
(join_type)
(from_item
(from_table
(identifier)))
(join_condition
(op_expression
(identifier)
(comparison_op)
(identifier))))
(join_item
(join_type)
(from_item
(from_table
(identifier)))
(join_condition
(identifier)))
(join_item
(join_type)
(from_item
(from_table
(identifier)))
(join_condition
(identifier)))
(join_item
(join_type)
(from_item
(from_table
(identifier)))
(join_condition
(identifier)))
(join_item
(join_type)
(from_item
(from_table
(identifier)))
(join_condition
(identifier)))
(join_item
(join_type)
(from_item
(from_table
(identifier)))
(join_condition
(identifier)))
(join_item
(join_type)
(from_item
(from_table
(identifier)))
(join_condition
(identifier)))
(join_item
(join_type)
(from_item
(from_table
(identifier)))
(join_condition
(identifier)))))))

View file

@ -1,301 +0,0 @@
================================================================================
where
================================================================================
select name from items where true;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_table
(identifier))))
(select_where
(where_filter
(true)))))
================================================================================
into
================================================================================
select name into bar from items where true;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(into
(identifier))
(select_from
(from_item
(from_table
(identifier))))
(select_where
(where_filter
(true)))))
================================================================================
into at the end
================================================================================
select * from items where true into _bar;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(star))
(select_from
(from_item
(from_table
(identifier))))
(select_where
(where_filter
(true)))
(into
(identifier))))
================================================================================
into strict
================================================================================
select name into strict bar from items where true;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(into
(identifier))
(select_from
(from_item
(from_table
(identifier))))
(select_where
(where_filter
(true)))))
================================================================================
into many
================================================================================
select foo, bar into a_foo, a_bar from items where true;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_item
(identifier))
(into
(identifier)
(identifier))
(select_from
(from_item
(from_table
(identifier))))
(select_where
(where_filter
(true)))))
================================================================================
having
================================================================================
select sum(len) from items having sum(len) < 5;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(function_call
(identifier)
(identifier)))
(select_from
(from_item
(from_table
(identifier))))
(select_having
(op_expression
(function_call
(identifier)
(identifier))
(comparison_op)
(number)))))
================================================================================
group by
================================================================================
select name from items group by 1, 2;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_table
(identifier))))
(select_group_by
(number)
(number))))
================================================================================
group by with parens
================================================================================
select name from items group by (1, 2);
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_table
(identifier))))
(select_group_by
(number)
(number))))
================================================================================
order by
================================================================================
select name from items order by 1, 2 asc, 3 desc, 4 + 4;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_table
(identifier))))
(select_order_by
(order_by_item
(number))
(order_by_item
(number)
(order_by_direction))
(order_by_item
(number)
(order_by_direction))
(order_by_item
(op_expression
(number)
(number))))))
================================================================================
limit
================================================================================
select name limit 1;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_limit
(number))))
================================================================================
limit offet
================================================================================
select name limit 1 offset 5;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_limit
(number))
(select_offset
(number))))
================================================================================
offset limit
================================================================================
select name offset 5 limit 1;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_offset
(number))
(select_limit
(number))))
================================================================================
limit all offset
================================================================================
select name limit all offset 5;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_limit)
(select_offset
(number))))
================================================================================
offset limit all
================================================================================
select name offset 5 limit all;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_offset
(number))
(select_limit)))
================================================================================
with cte
================================================================================
with foo as (select * from bar)
select * from foo;
--------------------------------------------------------------------------------
(source_file
(select_statement
(with_query
(with_query_item
(identifier)
(select_statement
(select_item
(star))
(select_from
(from_item
(from_table
(identifier)))))))
(select_item
(star))
(select_from
(from_item
(from_table
(identifier))))))
================================================================================
select alias star
================================================================================
SELECT foo.* FROM foo;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier)
(star))
(select_from
(from_item
(from_table
(identifier))))))

View file

@ -1,352 +0,0 @@
================================================================================
string
================================================================================
SELECT 'hello';
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(string))))
================================================================================
nested select
================================================================================
SELECT (SELECT 'hello');
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(select_statement
(select_item
(string))))))
================================================================================
many
================================================================================
SELECT 1234, -25, TRUE, FALSE, NULL, *;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(number))
(select_item
(number))
(select_item
(true))
(select_item
(false))
(select_item
(null))
(select_item
(star))))
================================================================================
identifiers
================================================================================
SELECT foo, foo.bar;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(identifier))
(select_item
(identifier))))
================================================================================
arrays
================================================================================
SELECT
ARRAY[],
array[1, 2],
array[array[1, 2], array[3, 4]],
array[]::integer[];
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(array_constructor))
(select_item
(array_constructor
(number)
(number)))
(select_item
(array_constructor
(array_constructor
(number)
(number))
(array_constructor
(number)
(number))))
(select_item
(op_expression
(array_constructor)
(cast)
(identifier)))))
================================================================================
binary_expression
================================================================================
SELECT a + b - c / d * e % f;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(op_expression
(op_expression
(identifier)
(identifier))
(op_expression
(op_expression
(op_expression
(identifier)
(identifier))
(identifier))
(identifier))))))
================================================================================
unary prec over binary
================================================================================
SELECT -22 + - (5 + 1);
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(op_expression
(number)
(op_expression
(minus)
(op_expression
(number)
(number)))))))
================================================================================
nested parens
================================================================================
SELECT ((((24 + 24))));
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(op_expression
(number)
(number)))))
================================================================================
logical expressions
================================================================================
SELECT 1 - 2 AND TRUE OR (5 = 2);
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(op_expression
(op_expression
(op_expression
(number)
(number))
(and)
(true))
(or)
(op_expression
(number)
(comparison_op)
(number))))))
================================================================================
function call
================================================================================
SELECT foo.bar(param) + baz();
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(op_expression
(function_call
(identifier)
(identifier))
(function_call
(identifier))))))
================================================================================
nested function call
================================================================================
SELECT coalesce(null, nullif(false, true), ops.my_fn(5));
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(function_call
(identifier)
(null)
(function_call
(identifier)
(false)
(true))
(function_call
(identifier)
(number))))))
================================================================================
casting
================================================================================
SELECT 1::text;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(op_expression
(number)
(cast)
(identifier)))))
================================================================================
string concatenation
================================================================================
SELECT 'hello' || 1 || now();
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(op_expression
(op_expression
(string)
(other_op)
(number))
(other_op)
(function_call
(identifier))))))
================================================================================
string quote
================================================================================
SELECT 'hello' || 'quote''s everywh''ere';
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(op_expression
(string)
(other_op)
(string)))))
================================================================================
contains_op
================================================================================
SELECT
1 in (1, 2),
'one' in ('one', 'two'),
2 between 4 and 8,
'foo' like '%oo',
'foo' ilike '%oo';
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(op_expression
(number)
(contains_op)
(number)
(number)))
(select_item
(op_expression
(string)
(contains_op)
(string)
(string)))
(select_item
(op_expression
(op_expression
(number)
(contains_op)
(number))
(and)
(number)))
(select_item
(op_expression
(string)
(contains_op)
(string)))
(select_item
(op_expression
(string)
(contains_op)
(string)))))
================================================================================
is null, isnull, is not null, notnull
================================================================================
SELECT
foo is null,
foo is not null,
foo isnull,
foo notnull;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(op_expression
(identifier)
(comparison_null)))
(select_item
(op_expression
(identifier)
(comparison_null)))
(select_item
(op_expression
(identifier)
(comparison_null)))
(select_item
(op_expression
(identifier)
(comparison_null)))))
================================================================================
time expressions
================================================================================
SELECT
foo::interval,
foo at time zone 'utc',
interval '1 day',
interval '1' hour to second,
interval '1' day + interval '3' month;
--------------------------------------------------------------------------------
(source_file
(select_statement
(select_item
(op_expression
(identifier)
(cast)
(identifier)))
(select_item
(time_expression
(identifier)
(string)))
(select_item
(time_expression
(string)))
(select_item
(time_expression
(string)))
(select_item
(op_expression
(time_expression
(string))
(time_expression
(string))))))

View file

@ -1,168 +0,0 @@
================================================================================
update one field
================================================================================
update items set foo = 'bar';
--------------------------------------------------------------------------------
(source_file
(update_statement
(identifier)
(update_set
(identifier)
(update_value
(string)))))
================================================================================
alias
================================================================================
update items as t set foo = 'bar';
--------------------------------------------------------------------------------
(source_file
(update_statement
(identifier)
(identifier)
(update_set
(identifier)
(update_value
(string)))))
================================================================================
update many fields
================================================================================
update t set col1 = val1, col2 = default returning foo, *;
--------------------------------------------------------------------------------
(source_file
(update_statement
(identifier)
(update_set
(identifier)
(update_value
(identifier)))
(update_set
(identifier)
(update_value))
(returning
(select_item
(identifier))
(select_item
(star)))))
================================================================================
update many fields(1)
================================================================================
update t set (col1, col2) = (val1, val2);
--------------------------------------------------------------------------------
(source_file
(update_statement
(identifier)
(update_set
(identifier)
(identifier)
(update_value
(identifier))
(update_value
(identifier)))))
================================================================================
update where
================================================================================
update t set foo = bar where column1 = 'magic';
--------------------------------------------------------------------------------
(source_file
(update_statement
(identifier)
(update_set
(identifier)
(update_value
(identifier)))
(where_filter
(op_expression
(identifier)
(comparison_op)
(string)))))
================================================================================
update where subselect
================================================================================
UPDATE t SET a = b + 1 WHERE id = (SELECT foo FROM bar WHERE c = 'd');
--------------------------------------------------------------------------------
(source_file
(update_statement
(identifier)
(update_set
(identifier)
(update_value
(op_expression
(identifier)
(number))))
(where_filter
(op_expression
(identifier)
(comparison_op)
(select_statement
(select_item
(identifier))
(select_from
(from_item
(from_table
(identifier))))
(select_where
(where_filter
(op_expression
(identifier)
(comparison_op)
(string)))))))))
================================================================================
update from
================================================================================
UPDATE foo SET bar = bar + 1 FROM t WHERE b = 'z';
--------------------------------------------------------------------------------
(source_file
(update_statement
(identifier)
(update_set
(identifier)
(update_value
(op_expression
(identifier)
(number))))
(from_item
(from_table
(identifier)))
(where_filter
(op_expression
(identifier)
(comparison_op)
(string)))))
================================================================================
with cte
================================================================================
with foo as (select * from bar)
update foo set bar = 1;
--------------------------------------------------------------------------------
(source_file
(update_statement
(with_query
(with_query_item
(identifier)
(select_statement
(select_item
(star))
(select_from
(from_item
(from_table
(identifier)))))))
(identifier)
(update_set
(identifier)
(update_value
(number)))))

View file

@ -1,208 +0,0 @@
================================================================================
basic
================================================================================
with w as (select * from foo) select * from w;
--------------------------------------------------------------------------------
(source_file
(select_statement
(with_query
(with_query_item
(identifier)
(select_statement
(select_item
(star))
(select_from
(from_item
(from_table
(identifier)))))))
(select_item
(star))
(select_from
(from_item
(from_table
(identifier))))))
================================================================================
with column names
================================================================================
with w(foo, bar) as (select * from foo) select * from w;
--------------------------------------------------------------------------------
(source_file
(select_statement
(with_query
(with_query_item
(identifier)
(identifier)
(identifier)
(select_statement
(select_item
(star))
(select_from
(from_item
(from_table
(identifier)))))))
(select_item
(star))
(select_from
(from_item
(from_table
(identifier))))))
================================================================================
materialized
================================================================================
with w as materialized (select * from foo) select * from w;
--------------------------------------------------------------------------------
(source_file
(select_statement
(with_query
(with_query_item
(identifier)
(select_statement
(select_item
(star))
(select_from
(from_item
(from_table
(identifier)))))))
(select_item
(star))
(select_from
(from_item
(from_table
(identifier))))))
================================================================================
not materialized
================================================================================
with w as not materialized (select * from foo) select * from w;
--------------------------------------------------------------------------------
(source_file
(select_statement
(with_query
(with_query_item
(identifier)
(select_statement
(select_item
(star))
(select_from
(from_item
(from_table
(identifier)))))))
(select_item
(star))
(select_from
(from_item
(from_table
(identifier))))))
================================================================================
with delete
================================================================================
with new as (delete from productes returning *) select 1;
--------------------------------------------------------------------------------
(source_file
(select_statement
(with_query
(with_query_item
(identifier)
(delete_statement
(identifier)
(select_item
(star)))))
(select_item
(number))))
================================================================================
select statement using with clause with insert into
================================================================================
with new as (insert into foo values(1)) select 1;
--------------------------------------------------------------------------------
(source_file
(select_statement
(with_query
(with_query_item
(identifier)
(insert_statement
(identifier)
(insert_items
(insert_values
(insert_item (number))
)
)
)
)
)
(select_item (number))
)
)
================================================================================
with update
================================================================================
with new as (update foo set bar = 1 returning *) select 1;
--------------------------------------------------------------------------------
(source_file
(select_statement
(with_query
(with_query_item
(identifier)
(update_statement
(identifier)
(update_set
(identifier)
(update_value
(number)))
(returning
(select_item
(star))))))
(select_item
(number))))
================================================================================
many
================================================================================
with w as (
select * from foo
), x as (
select * from bar
) select * from foo, bar;
--------------------------------------------------------------------------------
(source_file
(select_statement
(with_query
(with_query_item
(identifier)
(select_statement
(select_item
(star))
(select_from
(from_item
(from_table
(identifier))))))
(with_query_item
(identifier)
(select_statement
(select_item
(star))
(select_from
(from_item
(from_table
(identifier)))))))
(select_item
(star))
(select_from
(from_item
(from_table
(identifier)))
(from_item
(from_table
(identifier))))))

Binary file not shown.