getting into shape
This commit is contained in:
parent
78f290713f
commit
6303f6c3d8
27 changed files with 50673 additions and 1040 deletions
3
Makefile
3
Makefile
|
@ -1,4 +1,4 @@
|
|||
.DEFAULT_GOAL := test
|
||||
.DEFAULT_GOAL := build
|
||||
.PHONY: build test bless
|
||||
|
||||
build:
|
||||
|
@ -7,7 +7,6 @@ build:
|
|||
test:
|
||||
@$(MAKE) --no-print-directory build
|
||||
tree-sitter test
|
||||
# watchexec --clear dune test
|
||||
|
||||
bless:
|
||||
@$(MAKE) --no-print-directory build
|
||||
|
|
353
corpus/alter_table_statement.txt
Normal file
353
corpus/alter_table_statement.txt
Normal file
|
@ -0,0 +1,353 @@
|
|||
================================================================================
|
||||
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)))))
|
|
@ -1,16 +0,0 @@
|
|||
================================================================================
|
||||
Empty # todo: body as string, body with code
|
||||
================================================================================
|
||||
CREATE FUNCTION FOO () RETURNS BAZ AS $$ $$ LANGUAGE sql;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(create_function_statement
|
||||
(function_signature
|
||||
(identifier)
|
||||
(function_parameters))
|
||||
(identifier)
|
||||
(block
|
||||
(dollar_quote)
|
||||
(dollar_quote))
|
||||
(identifier)))
|
78
corpus/create_function/errors.txt
Normal file
78
corpus/create_function/errors.txt
Normal file
|
@ -0,0 +1,78 @@
|
|||
================================================================================
|
||||
wrong - trailing comma (1)
|
||||
================================================================================
|
||||
CREATE FUNCTION FOO (foo bar,) RETURNS void AS 'select' LANGUAGE sql;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(create_function_statement
|
||||
(function_signature
|
||||
(identifier)
|
||||
(function_parameters
|
||||
(var_declaration
|
||||
(identifier)
|
||||
(identifier))
|
||||
(ERROR)))
|
||||
(function_return
|
||||
(identifier))
|
||||
(string)
|
||||
(identifier)))
|
||||
|
||||
================================================================================
|
||||
wrong - trailing comma (2)
|
||||
================================================================================
|
||||
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))
|
||||
(ERROR)))
|
||||
(function_return
|
||||
(identifier))
|
||||
(string)
|
||||
(identifier)))
|
||||
|
||||
================================================================================
|
||||
wrong - missing type
|
||||
================================================================================
|
||||
CREATE FUNCTION FOO (foo,) RETURNS void AS 'select' LANGUAGE sql;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(create_function_statement
|
||||
(function_signature
|
||||
(identifier)
|
||||
(function_parameters
|
||||
(ERROR
|
||||
(identifier))))
|
||||
(function_return
|
||||
(identifier))
|
||||
(string)
|
||||
(identifier)))
|
||||
|
||||
================================================================================
|
||||
wrong - many volatilities
|
||||
================================================================================
|
||||
CREATE FUNCTION FOO () RETURNS void AS 'select' LANGUAGE sql STABLE VOLATILE;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(create_function_statement
|
||||
(function_signature
|
||||
(identifier)
|
||||
(function_parameters))
|
||||
(function_return
|
||||
(identifier))
|
||||
(string)
|
||||
(identifier)
|
||||
(function_volatility))
|
||||
(ERROR))
|
|
@ -1,7 +1,26 @@
|
|||
================================================================================
|
||||
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 () AS $$ $$ LANGUAGE sql;
|
||||
CREATE OR REPLACE FUNCTION FOO () RETURNS void AS 'select' LANGUAGE sql;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
|
@ -10,15 +29,15 @@ CREATE OR REPLACE FUNCTION FOO () AS $$ $$ LANGUAGE sql;
|
|||
(function_signature
|
||||
(identifier)
|
||||
(function_parameters))
|
||||
(block
|
||||
(dollar_quote)
|
||||
(dollar_quote))
|
||||
(function_return
|
||||
(identifier))
|
||||
(string)
|
||||
(identifier)))
|
||||
|
||||
================================================================================
|
||||
immutable
|
||||
================================================================================
|
||||
CREATE FUNCTION FOO () AS $$ $$ LANGUAGE sql IMMUTABLE;
|
||||
CREATE FUNCTION FOO () RETURNS void AS 'select' LANGUAGE sql IMMUTABLE;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
|
@ -26,16 +45,16 @@ CREATE FUNCTION FOO () AS $$ $$ LANGUAGE sql IMMUTABLE;
|
|||
(function_signature
|
||||
(identifier)
|
||||
(function_parameters))
|
||||
(block
|
||||
(dollar_quote)
|
||||
(dollar_quote))
|
||||
(function_return
|
||||
(identifier))
|
||||
(string)
|
||||
(identifier)
|
||||
(function_volatility)))
|
||||
|
||||
================================================================================
|
||||
stable
|
||||
================================================================================
|
||||
CREATE FUNCTION FOO () AS $$ $$ LANGUAGE sql STABLE;
|
||||
CREATE FUNCTION FOO () RETURNS void AS 'select' LANGUAGE sql STABLE;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
|
@ -43,16 +62,16 @@ CREATE FUNCTION FOO () AS $$ $$ LANGUAGE sql STABLE;
|
|||
(function_signature
|
||||
(identifier)
|
||||
(function_parameters))
|
||||
(block
|
||||
(dollar_quote)
|
||||
(dollar_quote))
|
||||
(function_return
|
||||
(identifier))
|
||||
(string)
|
||||
(identifier)
|
||||
(function_volatility)))
|
||||
|
||||
================================================================================
|
||||
volatile
|
||||
================================================================================
|
||||
CREATE FUNCTION FOO () AS $$ $$ LANGUAGE sql VOLATILE;
|
||||
CREATE FUNCTION FOO () RETURNS void AS 'select' LANGUAGE sql VOLATILE;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
|
@ -60,16 +79,16 @@ CREATE FUNCTION FOO () AS $$ $$ LANGUAGE sql VOLATILE;
|
|||
(function_signature
|
||||
(identifier)
|
||||
(function_parameters))
|
||||
(block
|
||||
(dollar_quote)
|
||||
(dollar_quote))
|
||||
(function_return
|
||||
(identifier))
|
||||
(string)
|
||||
(identifier)
|
||||
(function_volatility)))
|
||||
|
||||
================================================================================
|
||||
wrong - many volatilities
|
||||
returns setof
|
||||
================================================================================
|
||||
CREATE FUNCTION FOO () AS $$ $$ LANGUAGE sql STABLE VOLATILE;
|
||||
CREATE FUNCTION FOO () RETURNS SETOF text AS 'select' LANGUAGE sql;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
|
@ -77,9 +96,30 @@ CREATE FUNCTION FOO () AS $$ $$ LANGUAGE sql STABLE VOLATILE;
|
|||
(function_signature
|
||||
(identifier)
|
||||
(function_parameters))
|
||||
(block
|
||||
(dollar_quote)
|
||||
(dollar_quote))
|
||||
(identifier)
|
||||
(function_volatility))
|
||||
(ERROR))
|
||||
(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)))
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
================================================================================
|
||||
Empty
|
||||
empty
|
||||
================================================================================
|
||||
CREATE FUNCTION FOO () AS $$ $$ LANGUAGE sql;
|
||||
CREATE FUNCTION FOO () RETURNS void AS 'select' LANGUAGE sql;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
|
@ -9,15 +9,15 @@ CREATE FUNCTION FOO () AS $$ $$ LANGUAGE sql;
|
|||
(function_signature
|
||||
(identifier)
|
||||
(function_parameters))
|
||||
(block
|
||||
(dollar_quote)
|
||||
(dollar_quote))
|
||||
(function_return
|
||||
(identifier))
|
||||
(string)
|
||||
(identifier)))
|
||||
|
||||
================================================================================
|
||||
With argument
|
||||
with argument
|
||||
================================================================================
|
||||
CREATE FUNCTION FOO (_foo bar.baz) AS $$ $$ LANGUAGE sql;
|
||||
CREATE FUNCTION FOO (_foo bar.baz) RETURNS void AS 'select' LANGUAGE sql;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
|
@ -25,18 +25,18 @@ CREATE FUNCTION FOO (_foo bar.baz) AS $$ $$ LANGUAGE sql;
|
|||
(function_signature
|
||||
(identifier)
|
||||
(function_parameters
|
||||
(function_parameter
|
||||
(var_declaration
|
||||
(identifier)
|
||||
(identifier))))
|
||||
(block
|
||||
(dollar_quote)
|
||||
(dollar_quote))
|
||||
(function_return
|
||||
(identifier))
|
||||
(string)
|
||||
(identifier)))
|
||||
|
||||
================================================================================
|
||||
With arguments
|
||||
default value
|
||||
================================================================================
|
||||
CREATE FUNCTION FOO (foo bar, foo bar) AS $$ $$ LANGUAGE sql;
|
||||
CREATE FUNCTION FOO (_foo bar.baz default '42') RETURNS void AS 'select' LANGUAGE sql;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
|
@ -44,82 +44,41 @@ CREATE FUNCTION FOO (foo bar, foo bar) AS $$ $$ LANGUAGE sql;
|
|||
(function_signature
|
||||
(identifier)
|
||||
(function_parameters
|
||||
(function_parameter
|
||||
(var_declaration
|
||||
(identifier)
|
||||
(identifier))
|
||||
(function_parameter
|
||||
(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))))
|
||||
(block
|
||||
(dollar_quote)
|
||||
(dollar_quote))
|
||||
(identifier)))
|
||||
|
||||
================================================================================
|
||||
Wrong - trailing comma (1)
|
||||
================================================================================
|
||||
CREATE FUNCTION FOO (foo bar,) AS $$ $$ LANGUAGE sql;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(create_function_statement
|
||||
(function_signature
|
||||
(identifier)
|
||||
(function_parameters
|
||||
(function_parameter
|
||||
(identifier)
|
||||
(identifier))
|
||||
(ERROR)))
|
||||
(block
|
||||
(dollar_quote)
|
||||
(dollar_quote))
|
||||
(identifier)))
|
||||
|
||||
================================================================================
|
||||
Wrong - trailing comma (2)
|
||||
================================================================================
|
||||
CREATE FUNCTION FOO (foo bar, foo bar,) AS $$ $$ LANGUAGE sql;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(create_function_statement
|
||||
(function_signature
|
||||
(identifier)
|
||||
(function_parameters
|
||||
(function_parameter
|
||||
(identifier)
|
||||
(identifier))
|
||||
(function_parameter
|
||||
(identifier)
|
||||
(identifier))
|
||||
(ERROR)))
|
||||
(block
|
||||
(dollar_quote)
|
||||
(dollar_quote))
|
||||
(identifier)))
|
||||
|
||||
================================================================================
|
||||
Wrong - missing type
|
||||
================================================================================
|
||||
CREATE FUNCTION FOO (foo,) AS $$ $$ LANGUAGE sql;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(create_function_statement
|
||||
(function_signature
|
||||
(identifier)
|
||||
(function_parameters
|
||||
(ERROR
|
||||
(identifier))))
|
||||
(block
|
||||
(dollar_quote)
|
||||
(dollar_quote))
|
||||
(function_return
|
||||
(identifier))
|
||||
(string)
|
||||
(identifier)))
|
||||
|
||||
================================================================================
|
||||
arrays
|
||||
================================================================================
|
||||
CREATE FUNCTION FOO (foo bar[], foo bar[][]) AS $$ $$ LANGUAGE sql;
|
||||
CREATE FUNCTION FOO (foo bar[], foo bar[][]) RETURNS void AS 'select' LANGUAGE sql;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
|
@ -127,13 +86,13 @@ CREATE FUNCTION FOO (foo bar[], foo bar[][]) AS $$ $$ LANGUAGE sql;
|
|||
(function_signature
|
||||
(identifier)
|
||||
(function_parameters
|
||||
(function_parameter
|
||||
(var_declaration
|
||||
(identifier)
|
||||
(identifier))
|
||||
(function_parameter
|
||||
(var_declaration
|
||||
(identifier)
|
||||
(identifier))))
|
||||
(block
|
||||
(dollar_quote)
|
||||
(dollar_quote))
|
||||
(function_return
|
||||
(identifier))
|
||||
(string)
|
||||
(identifier)))
|
||||
|
|
93
corpus/create_index_statement.txt
Normal file
93
corpus/create_index_statement.txt
Normal file
|
@ -0,0 +1,93 @@
|
|||
================================================================================
|
||||
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)))))
|
77
corpus/create_schema_statement.txt
Normal file
77
corpus/create_schema_statement.txt
Normal file
|
@ -0,0 +1,77 @@
|
|||
================================================================================
|
||||
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))))
|
235
corpus/create_sequence_statement.txt
Normal file
235
corpus/create_sequence_statement.txt
Normal file
|
@ -0,0 +1,235 @@
|
|||
================================================================================
|
||||
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
|
||||
(ERROR)
|
||||
(number))
|
||||
(sequence_min
|
||||
(number))
|
||||
(sequence_max)
|
||||
(sequence_start
|
||||
(number))
|
||||
(sequence_cache
|
||||
(number))
|
||||
(sequence_cycle)
|
||||
(sequence_owned)))
|
293
corpus/create_table_statement.txt
Normal file
293
corpus/create_table_statement.txt
Normal file
|
@ -0,0 +1,293 @@
|
|||
================================================================================
|
||||
empty table
|
||||
================================================================================
|
||||
create table foo();
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(create_table_statement
|
||||
(identifier)))
|
||||
|
||||
================================================================================
|
||||
temp
|
||||
================================================================================
|
||||
create temp table foo();
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(create_table_statement
|
||||
(temporary)
|
||||
(identifier)))
|
||||
|
||||
================================================================================
|
||||
temporary
|
||||
================================================================================
|
||||
create temporary table foo();
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(create_table_statement
|
||||
(temporary)
|
||||
(identifier)))
|
||||
|
||||
================================================================================
|
||||
if not exists
|
||||
================================================================================
|
||||
create table if not exists foo();
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(create_table_statement
|
||||
(if_not_exists)
|
||||
(identifier)))
|
||||
|
||||
================================================================================
|
||||
unlogged
|
||||
================================================================================
|
||||
create unlogged table foo();
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(create_table_statement
|
||||
(identifier)))
|
||||
|
||||
================================================================================
|
||||
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_types
|
||||
(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_types
|
||||
(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)))))))
|
184
corpus/create_trigger_statement.txt
Normal file
184
corpus/create_trigger_statement.txt
Normal file
|
@ -0,0 +1,184 @@
|
|||
================================================================================
|
||||
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)))))
|
104
corpus/delete_statement.txt
Normal file
104
corpus/delete_statement.txt
Normal file
|
@ -0,0 +1,104 @@
|
|||
================================================================================
|
||||
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))))
|
106
corpus/execute_statement.txt
Normal file
106
corpus/execute_statement.txt
Normal file
|
@ -0,0 +1,106 @@
|
|||
================================================================================
|
||||
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)
|
||||
(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))
|
||||
(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))))
|
177
corpus/grant_statement.txt
Normal file
177
corpus/grant_statement.txt
Normal file
|
@ -0,0 +1,177 @@
|
|||
================================================================================
|
||||
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))))
|
160
corpus/insert_statement/insert.txt
Normal file
160
corpus/insert_statement/insert.txt
Normal file
|
@ -0,0 +1,160 @@
|
|||
================================================================================
|
||||
basic
|
||||
================================================================================
|
||||
insert into my_table values(1);
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(insert_statement
|
||||
(identifier)
|
||||
(insert_items
|
||||
(insert_item
|
||||
(number)))))
|
||||
|
||||
================================================================================
|
||||
alias
|
||||
================================================================================
|
||||
insert into foo.my_table as alias values(1);
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(insert_statement
|
||||
(identifier)
|
||||
(as
|
||||
(identifier))
|
||||
(insert_items
|
||||
(insert_item
|
||||
(number)))))
|
||||
|
||||
================================================================================
|
||||
default values
|
||||
================================================================================
|
||||
insert into foo.my_table default values;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(insert_statement
|
||||
(identifier)
|
||||
(insert_items)))
|
||||
|
||||
================================================================================
|
||||
many values
|
||||
================================================================================
|
||||
insert into foo.my_table values(1, 2);
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(insert_statement
|
||||
(identifier)
|
||||
(insert_items
|
||||
(insert_item
|
||||
(number))
|
||||
(insert_item
|
||||
(number)))))
|
||||
|
||||
================================================================================
|
||||
different kind of values
|
||||
================================================================================
|
||||
insert into foo.my_table values(1, DEFAULT, (select 1, 2));
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(insert_statement
|
||||
(identifier)
|
||||
(insert_items
|
||||
(insert_item
|
||||
(number))
|
||||
(insert_item)
|
||||
(insert_item
|
||||
(select_statement
|
||||
(select_item
|
||||
(number))
|
||||
(select_item
|
||||
(number)))))))
|
||||
|
||||
================================================================================
|
||||
insert 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))))))))
|
||||
|
||||
================================================================================
|
||||
returning
|
||||
================================================================================
|
||||
insert into foo values(1) returning *, 1;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(insert_statement
|
||||
(identifier)
|
||||
(insert_items
|
||||
(insert_item
|
||||
(number)))
|
||||
(insert_returning
|
||||
(select_item
|
||||
(star))
|
||||
(select_item
|
||||
(number)))))
|
||||
|
||||
================================================================================
|
||||
with cte
|
||||
================================================================================
|
||||
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_item
|
||||
(number)))))
|
||||
|
||||
================================================================================
|
||||
returning into
|
||||
================================================================================
|
||||
insert into foo(bar, baz) select * from another
|
||||
returning id into _var;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(insert_statement
|
||||
(identifier)
|
||||
(identifier)
|
||||
(identifier)
|
||||
(insert_items
|
||||
(select_statement
|
||||
(select_item
|
||||
(star))
|
||||
(select_from
|
||||
(from_item
|
||||
(from_table
|
||||
(identifier))))))
|
||||
(insert_returning
|
||||
(select_item
|
||||
(identifier)))
|
||||
(into
|
||||
(identifier))))
|
169
corpus/insert_statement/on_conflict.txt
Normal file
169
corpus/insert_statement/on_conflict.txt
Normal file
|
@ -0,0 +1,169 @@
|
|||
================================================================================
|
||||
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)))))
|
190
corpus/plpgsql/block.txt
Normal file
190
corpus/plpgsql/block.txt
Normal file
|
@ -0,0 +1,190 @@
|
|||
================================================================================
|
||||
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 text;
|
||||
age bigint;
|
||||
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);
|
||||
RETURN 2;
|
||||
END
|
||||
$$;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(do_block
|
||||
(block
|
||||
(dollar_quote)
|
||||
(body
|
||||
(select_statement
|
||||
(select_item
|
||||
(number)))
|
||||
(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))))
|
39
corpus/plpgsql/return_statement.txt
Normal file
39
corpus/plpgsql/return_statement.txt
Normal file
|
@ -0,0 +1,39 @@
|
|||
================================================================================
|
||||
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))))
|
179
corpus/select_statement/from.txt
Normal file
179
corpus/select_statement/from.txt
Normal file
|
@ -0,0 +1,179 @@
|
|||
================================================================================
|
||||
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))))))
|
311
corpus/select_statement/join.txt
Normal file
311
corpus/select_statement/join.txt
Normal file
|
@ -0,0 +1,311 @@
|
|||
================================================================================
|
||||
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_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_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_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_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_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_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_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_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_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_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_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_table
|
||||
(identifier)))
|
||||
(join_item
|
||||
(from_table
|
||||
(identifier)))
|
||||
(join_item
|
||||
(join_type)
|
||||
(from_table
|
||||
(identifier))
|
||||
(join_condition
|
||||
(op_expression
|
||||
(identifier)
|
||||
(comparison_op)
|
||||
(identifier))))
|
||||
(join_item
|
||||
(join_type)
|
||||
(from_table
|
||||
(identifier))
|
||||
(join_condition
|
||||
(identifier)))
|
||||
(join_item
|
||||
(join_type)
|
||||
(from_table
|
||||
(identifier))
|
||||
(join_condition
|
||||
(identifier)))
|
||||
(join_item
|
||||
(join_type)
|
||||
(from_table
|
||||
(identifier))
|
||||
(join_condition
|
||||
(identifier)))
|
||||
(join_item
|
||||
(join_type)
|
||||
(from_table
|
||||
(identifier))
|
||||
(join_condition
|
||||
(identifier)))
|
||||
(join_item
|
||||
(join_type)
|
||||
(from_table
|
||||
(identifier))
|
||||
(join_condition
|
||||
(identifier)))
|
||||
(join_item
|
||||
(join_type)
|
||||
(from_table
|
||||
(identifier))
|
||||
(join_condition
|
||||
(identifier)))
|
||||
(join_item
|
||||
(join_type)
|
||||
(from_table
|
||||
(identifier))
|
||||
(join_condition
|
||||
(identifier)))))))
|
243
corpus/select_statement/select.txt
Normal file
243
corpus/select_statement/select.txt
Normal file
|
@ -0,0 +1,243 @@
|
|||
================================================================================
|
||||
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 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))))
|
||||
|
||||
================================================================================
|
||||
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)))
|
||||
(ERROR
|
||||
(number)))
|
||||
|
||||
================================================================================
|
||||
limit offet
|
||||
================================================================================
|
||||
select name limit 1 offset 5;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(select_statement
|
||||
(select_item
|
||||
(identifier))
|
||||
(select_limit
|
||||
(number)
|
||||
(number))))
|
||||
|
||||
================================================================================
|
||||
offset limit
|
||||
================================================================================
|
||||
select name offset 5 limit 1;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(select_statement
|
||||
(select_item
|
||||
(identifier))
|
||||
(select_limit
|
||||
(number)
|
||||
(number))))
|
||||
|
||||
================================================================================
|
||||
limit all offset
|
||||
================================================================================
|
||||
select name limit all offset 5;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(select_statement
|
||||
(select_item
|
||||
(identifier))
|
||||
(select_limit
|
||||
(number))))
|
||||
|
||||
================================================================================
|
||||
offset limit all
|
||||
================================================================================
|
||||
select name offset 5 limit all;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(select_statement
|
||||
(select_item
|
||||
(identifier))
|
||||
(select_limit
|
||||
(number))))
|
||||
|
||||
================================================================================
|
||||
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))))))
|
216
corpus/select_statement/value_expression.txt
Normal file
216
corpus/select_statement/value_expression.txt
Normal file
|
@ -0,0 +1,216 @@
|
|||
================================================================================
|
||||
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
|
||||
(op_expression
|
||||
(minus)
|
||||
(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))))
|
||||
|
||||
================================================================================
|
||||
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
|
||||
(op_expression
|
||||
(minus)
|
||||
(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)))))
|
152
corpus/with_statement.txt
Normal file
152
corpus/with_statement.txt
Normal file
|
@ -0,0 +1,152 @@
|
|||
================================================================================
|
||||
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))))))
|
||||
|
||||
================================================================================
|
||||
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))))
|
||||
|
||||
================================================================================
|
||||
with insert
|
||||
================================================================================
|
||||
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_item
|
||||
(number))))))
|
||||
(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))))))
|
677
grammar.js
677
grammar.js
|
@ -1,59 +1,548 @@
|
|||
function kw(keyword, aliasAsWord = true) {
|
||||
let result = new RegExp(keyword
|
||||
.split('')
|
||||
.map(l => l !== l.toUpperCase() ? `[${l}${l.toUpperCase()}]` : l)
|
||||
.join('')
|
||||
);
|
||||
if (aliasAsWord) {
|
||||
result = alias(result, keyword);
|
||||
function kw(word, aliasAsWord = true) {
|
||||
let pattern = ""
|
||||
for (const letter of word) {
|
||||
pattern += `[${letter}${letter.toUpperCase()}]`
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function delimited(left, rule, right = left) {
|
||||
return seq(left, rule, right)
|
||||
let result = new RegExp(pattern)
|
||||
if (aliasAsWord) {
|
||||
result = alias(result, word);
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
function separated(separator, rule) {
|
||||
return choice(
|
||||
optional(rule),
|
||||
seq(rule, repeat1(seq(",", rule))))
|
||||
return optional(separated1(separator, rule));
|
||||
}
|
||||
|
||||
function separated1(separator, rule) {
|
||||
return seq(rule, repeat(seq(separator, rule)));
|
||||
}
|
||||
|
||||
function commaSep1(rule) {
|
||||
return separated1(",", rule);
|
||||
}
|
||||
|
||||
function commaSep(rule) {
|
||||
return optional(commaSep1(rule));
|
||||
}
|
||||
|
||||
module.exports = grammar({
|
||||
name: 'plpgsql',
|
||||
name: "plpgsql",
|
||||
// NOTE(chrde): https://github.com/tree-sitter/tree-sitter-javascript/blob/1ddbf1588c353edab37791cdcc9f17e56fb4ea73/grammar.js#L9
|
||||
extras: $ => [
|
||||
$.comment,
|
||||
/[\s\uFEFF\u2060\u200B\u00A0]/
|
||||
],
|
||||
|
||||
rules: {
|
||||
source_file: $ => repeat($._statement),
|
||||
|
||||
_statement: $ => seq(
|
||||
source_file: $ => repeat(
|
||||
choice(
|
||||
$.create_function_statement,
|
||||
$.psql_statement,
|
||||
seq($._statement, ";")
|
||||
),
|
||||
";"
|
||||
),
|
||||
|
||||
_statement: $ => choice(
|
||||
$.psql_statement,
|
||||
$.create_function_statement,
|
||||
$.create_table_statement,
|
||||
$.create_schema_statement,
|
||||
$.select_statement,
|
||||
$.insert_statement,
|
||||
$.delete_statement,
|
||||
$.grant_statement,
|
||||
$.create_trigger_statement,
|
||||
$.create_sequence_statement,
|
||||
$.create_index_statement,
|
||||
$.alter_table_statement,
|
||||
$.do_block,
|
||||
),
|
||||
|
||||
// TODO(chrde): update, values
|
||||
_with_query_statement: $ => choice(
|
||||
$.select_statement,
|
||||
$.insert_statement,
|
||||
$.delete_statement,
|
||||
),
|
||||
|
||||
insert_statement: $ => seq(
|
||||
optional($.with_query),
|
||||
kw("insert"), kw("into"), $.identifier, optional($.as),
|
||||
optional($._list_of_identifiers),
|
||||
$.insert_items, optional($.insert_conflict),
|
||||
optional($.insert_returning),
|
||||
optional($.into),
|
||||
),
|
||||
insert_items: $ => choice(
|
||||
seq(kw("default"), kw("values")),
|
||||
seq(kw("values"), "(", commaSep($.insert_item), ")"),
|
||||
$.select_statement
|
||||
),
|
||||
insert_item: $ => choice(
|
||||
kw("default"),
|
||||
$._value_expression,
|
||||
),
|
||||
insert_conflict: $ => choice(
|
||||
seq(kw("on"), kw("conflict"), optional($.conflict_target), kw("do"), kw("nothing")),
|
||||
seq(
|
||||
kw("on"), kw("conflict"), $.conflict_target, kw("do"), kw("update"), kw("set"),
|
||||
commaSep1($.update_set), optional($.where_filter)
|
||||
),
|
||||
),
|
||||
conflict_target: $ => choice(
|
||||
seq(kw("on"), kw("constraint"), $.identifier),
|
||||
seq("(", commaSep($._value_expression), ")", ),
|
||||
),
|
||||
update_set: $ => choice(
|
||||
seq($.identifier, "=", $.update_value),
|
||||
seq($._list_of_identifiers, "=", optional(kw("row")), "(", commaSep1($.update_value), ")"),
|
||||
),
|
||||
update_value: $ => choice(kw("default"), $._value_expression),
|
||||
insert_returning: $ => seq(kw("returning"), commaSep1($.select_item)),
|
||||
|
||||
create_table_statement: $ => seq(
|
||||
kw("create"), optional($.temporary), optional(kw("unlogged")), kw("table"),
|
||||
optional($.if_not_exists), $.identifier,
|
||||
"(", commaSep($.create_table_item), ")",
|
||||
),
|
||||
|
||||
create_table_item: $ => choice(
|
||||
$.table_column_item,
|
||||
$.table_constraint,
|
||||
),
|
||||
|
||||
create_schema_statement: $ => seq(
|
||||
kw("create"), kw("schema"), optional($.if_not_exists), choice(
|
||||
seq($.identifier, optional($.schema_role)),
|
||||
$.schema_role,
|
||||
),
|
||||
),
|
||||
|
||||
schema_role: $ => seq(
|
||||
kw("authorization"),
|
||||
choice($.identifier, kw("current_user"), kw("session_user")),
|
||||
),
|
||||
|
||||
create_index_statement: $ => seq(
|
||||
kw("create"), optional(kw("unique")), kw("index"), optional(kw("concurrently")),
|
||||
optional($.if_not_exists), optional($.identifier), kw("on"), $.identifier,
|
||||
optional($.index_using),
|
||||
"(", commaSep1($.index_col), ")",
|
||||
optional($.index_includes),
|
||||
optional($.where_filter),
|
||||
),
|
||||
|
||||
index_using: $ => seq(kw("using"), $.identifier),
|
||||
index_col: $ => choice(
|
||||
seq($.identifier, optional($.index_col_dir), optional($.index_col_nulls)),
|
||||
seq("(", $._value_expression, ")", optional($.index_col_dir), optional($.index_col_nulls)),
|
||||
),
|
||||
index_col_dir: $ => choice(kw("asc"), kw("desc")),
|
||||
index_col_nulls: $ => choice(
|
||||
seq(kw("nulls"), kw("first")),
|
||||
seq(kw("nulls"), kw("last")),
|
||||
),
|
||||
index_includes: $ => seq(kw("include"), $._list_of_identifiers),
|
||||
|
||||
delete_statement: $ => seq(
|
||||
optional($.with_query),
|
||||
kw("delete"), kw("from"), $.identifier, optional(kw("as")), optional($.identifier),
|
||||
optional($.delete_using),
|
||||
optional($.where_filter),
|
||||
optional(seq(kw("returning"), commaSep1($.select_item))),
|
||||
optional($.into),
|
||||
),
|
||||
|
||||
delete_using: $ => seq(kw("using"), commaSep1($.from_item)),
|
||||
|
||||
alter_table_statement: $ => seq(
|
||||
kw("alter"), kw("table"), optional($.if_exists), $.identifier,
|
||||
$.alter_table_change
|
||||
),
|
||||
|
||||
alter_table_change: $ => choice(
|
||||
commaSep1($.alter_table_action),
|
||||
$.alter_table_rename_column,
|
||||
$.alter_table_rename_constraint,
|
||||
$.alter_table_rename_table,
|
||||
$.alter_table_change_schema,
|
||||
),
|
||||
|
||||
alter_table_action: $ => choice(
|
||||
seq(kw("add"), $.table_constraint),
|
||||
seq(kw("add"), optional(kw("column")), optional($.if_not_exists), $.table_column_item),
|
||||
seq(kw("drop"), kw("constraint"), optional($.if_exists), $.identifier, optional($.alter_table_fk_ref_action)),
|
||||
seq(kw("drop"), optional(kw("column")), optional($.if_exists), $.identifier, optional($.alter_table_fk_ref_action)),
|
||||
seq(kw("alter"), optional(kw("column")), $.identifier, optional($.alter_column_action)),
|
||||
),
|
||||
|
||||
alter_column_action: $ => choice(
|
||||
seq(kw("set"), kw("default"), $._value_expression),
|
||||
seq(kw("drop"), kw("default")),
|
||||
seq(kw("set"), kw("not"), kw("null")),
|
||||
seq(kw("drop"), kw("not"), kw("null")),
|
||||
seq(kw("type"), $.alter_column_type),
|
||||
seq(kw("set"), kw("data"), kw("type"), $.alter_column_type),
|
||||
),
|
||||
|
||||
table_constraint: $ => choice(
|
||||
seq($.table_constraint_ty, optional($.constraint_when)),
|
||||
seq(kw("constraint"), $.identifier, $.table_constraint_ty, optional($.constraint_when)),
|
||||
),
|
||||
|
||||
constraint_when: $ => choice(
|
||||
kw("deferrable"),
|
||||
seq(kw("deferrable"), kw("initially"), kw("immediate")),
|
||||
seq(kw("deferrable"), kw("initially"), kw("deferred")),
|
||||
),
|
||||
|
||||
table_constraint_ty: $ => choice(
|
||||
seq(kw("check"), "(", $._value_expression, ")"),
|
||||
seq(kw("unique"), $._list_of_identifiers),
|
||||
seq(kw("primary"), kw("key"), $._list_of_identifiers),
|
||||
seq(kw("foreign"), kw("key"), $._list_of_identifiers, $.constraint_foreign_key),
|
||||
),
|
||||
|
||||
constraint_foreign_key: $ => seq(
|
||||
kw("references"), $.identifier,
|
||||
optional($._list_of_identifiers), repeat($.fk_action)
|
||||
),
|
||||
|
||||
fk_action: $ => choice(
|
||||
seq(kw("on"), kw("delete"), $.fk_ref_action),
|
||||
seq(kw("on"), kw("update"), $.fk_ref_action),
|
||||
),
|
||||
|
||||
fk_ref_action: $ => choice(
|
||||
seq(kw("no"), kw("action")),
|
||||
kw("restrict"),
|
||||
kw("cascade"),
|
||||
seq(kw("set"), kw("null")),
|
||||
seq(kw("set"), kw("default"))
|
||||
),
|
||||
|
||||
alter_column_type: $ => seq(
|
||||
$._type,
|
||||
optional(seq(kw("using"), $._value_expression)),
|
||||
),
|
||||
alter_table_fk_ref_action: $ => choice(kw("restrict"), kw("cascade")),
|
||||
table_column_item: $ => seq($.identifier, $._type, repeat($.column_constraint)),
|
||||
|
||||
column_constraint: $ => choice(
|
||||
seq(kw("constraint"), $.identifier, $.column_constraint_ty, optional($.constraint_when)),
|
||||
seq($.column_constraint_ty, optional($.constraint_when)),
|
||||
),
|
||||
|
||||
column_constraint_ty: $ => choice(
|
||||
seq(kw("not"), kw("null")),
|
||||
kw("null"),
|
||||
seq(kw("check"), "(", $._value_expression, ")"),
|
||||
seq(kw("default"), $._value_expression),
|
||||
kw("unique"),
|
||||
seq(kw("primary"), kw("key")),
|
||||
$.constraint_foreign_key,
|
||||
),
|
||||
|
||||
alter_table_rename_column: $ => seq(
|
||||
kw("rename"), optional(kw("column")),
|
||||
$.identifier, kw("to"), $.identifier,
|
||||
),
|
||||
alter_table_rename_constraint: $ => seq(
|
||||
kw("rename"), kw("constraint"),
|
||||
$.identifier, kw("to"), $.identifier,
|
||||
),
|
||||
alter_table_rename_table: $ => seq(kw("rename"), kw("to"), $.identifier),
|
||||
alter_table_change_schema: $ => seq(kw("set"), kw("schema"), $.identifier),
|
||||
|
||||
|
||||
grant_statement: $ => seq(
|
||||
kw("grant"), $.grant_privileges,
|
||||
kw("on"), $.grant_targets,
|
||||
kw("to"), $.grant_roles,
|
||||
),
|
||||
|
||||
grant_roles: $ => commaSep1(choice(
|
||||
kw("public"),
|
||||
kw("current_user"),
|
||||
kw("session_user"),
|
||||
seq(optional(kw("group")), $.identifier),
|
||||
)),
|
||||
|
||||
|
||||
grant_privileges: $ => choice(
|
||||
seq(kw("all"), optional("privileges")),
|
||||
commaSep1($.identifier),
|
||||
),
|
||||
|
||||
grant_targets: $ => choice(
|
||||
seq(
|
||||
kw("all"),
|
||||
choice(kw("tables"), kw("sequences"), kw("functions")),
|
||||
kw("in"), kw("schema"), $.identifier
|
||||
),
|
||||
seq(kw("sequence"), commaSep1($.identifier)),
|
||||
seq(optional(kw("table")), commaSep1($.identifier)),
|
||||
seq(kw("schema"), commaSep1($.identifier)),
|
||||
seq(
|
||||
choice(kw("function"), kw("procedure"), kw("routine")),
|
||||
commaSep1($.grant_function),
|
||||
),
|
||||
),
|
||||
|
||||
grant_function: $ => seq(
|
||||
$.identifier,
|
||||
"(",
|
||||
commaSep1(seq(optional($.identifier), $._type)),
|
||||
")",
|
||||
),
|
||||
|
||||
grant_all_in_schema: $ => seq(kw("in"), kw("schema")),
|
||||
|
||||
psql_statement: $ => seq(
|
||||
"\\",
|
||||
repeat1($.identifier),
|
||||
/[\n\r]/,
|
||||
),
|
||||
|
||||
create_sequence_statement: $ => seq(
|
||||
kw("create"), optional($.temporary), kw("sequence"), optional($.if_not_exists),
|
||||
$.identifier,
|
||||
repeat(choice(
|
||||
$.as,
|
||||
$.sequence_increment,
|
||||
$.sequence_min,
|
||||
$.sequence_max,
|
||||
$.sequence_start,
|
||||
$.sequence_cache,
|
||||
$.sequence_cycle,
|
||||
$.sequence_owned,
|
||||
)),
|
||||
),
|
||||
|
||||
sequence_increment: $ => seq(kw("increment"), optional(kw("by")), $.number),
|
||||
sequence_min: $ => choice(
|
||||
seq(kw("no"), kw("minvalue")),
|
||||
seq(kw("minvalue"), $.number,),
|
||||
),
|
||||
sequence_max: $ => choice(
|
||||
seq(kw("no"), kw("maxvalue")),
|
||||
seq(kw("maxvalue"), $.number,),
|
||||
),
|
||||
sequence_start: $ => seq(kw("start"), optional(kw("with")), $.number),
|
||||
sequence_cache: $ => seq(kw("cache"), $.number),
|
||||
sequence_cycle: $ => seq(optional(kw("no")), kw("cycle")),
|
||||
sequence_owned: $ => seq(
|
||||
kw("owned"), kw("by"),
|
||||
choice(
|
||||
kw("none"),
|
||||
$.identifier
|
||||
),
|
||||
),
|
||||
|
||||
create_trigger_statement: $ => seq(
|
||||
kw("create"), optional(kw("constraint")), kw("trigger"),
|
||||
$.identifier,
|
||||
$.trigger_when, $.trigger_event,
|
||||
kw("on"), $.identifier, optional($.trigger_scope),
|
||||
optional($.trigger_cond),
|
||||
$.trigger_exec,
|
||||
),
|
||||
|
||||
trigger_when: $ => choice(
|
||||
kw("before"),
|
||||
kw("after"),
|
||||
kw("instead of"),
|
||||
),
|
||||
|
||||
trigger_event: $ => separated1(
|
||||
kw("or"), choice(
|
||||
kw("insert"),
|
||||
kw("update"),
|
||||
kw("delete"),
|
||||
kw("truncate"),
|
||||
),
|
||||
),
|
||||
|
||||
trigger_scope: $ => seq(
|
||||
optional(seq(kw("for"), optional(kw("each")))),
|
||||
choice(kw("statement"), kw("row")),
|
||||
),
|
||||
|
||||
trigger_exec: $ => seq(
|
||||
kw("execute"),
|
||||
optional(choice(kw("procedure"), kw("function"))),
|
||||
$.function_call,
|
||||
),
|
||||
|
||||
trigger_cond: $ => seq(
|
||||
kw("when"),
|
||||
"(", $._value_expression, ")",
|
||||
),
|
||||
|
||||
_plpgsql_statement: $ => seq(
|
||||
choice(
|
||||
$._statement,
|
||||
$.assign_statement,
|
||||
$.return_statement,
|
||||
$.execute_statement,
|
||||
$.perform_statement,
|
||||
),
|
||||
";",
|
||||
),
|
||||
|
||||
execute_statement: $ => seq(
|
||||
kw("execute"),
|
||||
$._value_expression,
|
||||
optional($.into),
|
||||
optional(seq(kw("using"), commaSep1($._value_expression))),
|
||||
),
|
||||
assign_statement: $ => seq($.identifier, "=", $._value_expression),
|
||||
return_statement: $ => seq(kw("return"), choice(
|
||||
seq(kw("query"), $.select_statement),
|
||||
$._value_expression),
|
||||
),
|
||||
perform_statement: $ => seq(kw("perform"), commaSep($.select_item)),
|
||||
|
||||
do_block: $ => seq(
|
||||
kw("do"),
|
||||
$.block,
|
||||
),
|
||||
|
||||
select_statement: $ => prec.left(seq(
|
||||
optional($.with_query),
|
||||
kw("select"),
|
||||
commaSep($.select_item),
|
||||
optional($.into),
|
||||
optional($.select_from),
|
||||
optional($.select_where),
|
||||
optional($.select_group_by),
|
||||
optional($.select_having),
|
||||
optional($.select_order_by),
|
||||
optional($.select_limit),
|
||||
)),
|
||||
|
||||
with_query: $ => seq(kw("with"), commaSep1($.with_query_item)),
|
||||
with_query_item: $ => seq(
|
||||
$.identifier,
|
||||
// TODO(chrde): columns
|
||||
kw("as"),
|
||||
optional(choice(kw("materialized"), seq(kw("not"), kw("materialized")))),
|
||||
"(", $._with_query_statement, ")"
|
||||
),
|
||||
|
||||
into: $ => seq(kw("into"), optional(kw("strict")), commaSep1($.identifier)),
|
||||
select_having: $ => seq(kw("having"), $._value_expression),
|
||||
select_limit: $ => choice(
|
||||
seq(kw("limit"), $._value_expression, kw("offset"), $._value_expression),
|
||||
seq(kw("limit"), kw("all"), kw("offset"), $._value_expression),
|
||||
seq(kw("offset"), $._value_expression, kw("limit"), kw("all")),
|
||||
seq(kw("offset"), $._value_expression, kw("limit"), $._value_expression),
|
||||
),
|
||||
select_group_by: $ => seq(kw("group"), kw("by"), commaSep1($._value_expression)),
|
||||
select_order_by: $ => seq(kw("order"), kw("by"), commaSep1($.order_by_item)),
|
||||
order_by_item: $ => seq($._value_expression, optional($.order_by_direction)),
|
||||
order_by_direction: $ => choice(kw("asc"), kw("desc")),
|
||||
select_where: $ => $.where_filter,
|
||||
select_item: $ => seq(
|
||||
$._value_expression,
|
||||
optional(kw("as")),
|
||||
optional($.identifier)
|
||||
),
|
||||
select_from: $ => seq(kw("from"), commaSep1($.from_item)),
|
||||
from_item: $ => seq(
|
||||
// TODO(chrde): https://www.postgresql.org/docs/current/sql-select.html
|
||||
choice(
|
||||
$.from_select,
|
||||
$.from_table,
|
||||
$.from_function,
|
||||
),
|
||||
repeat($.join_item),
|
||||
),
|
||||
from_select: $ => seq("(", $.select_statement, ")", optional(kw("as")), $.identifier),
|
||||
from_table: $ => seq($.identifier, optional(kw("as")), optional($.identifier)),
|
||||
from_function: $ => seq(
|
||||
$.function_call,
|
||||
optional(choice(
|
||||
seq(kw("as"), $.identifier, optional($._list_of_identifiers)),
|
||||
seq($.identifier, optional($._list_of_identifiers)),
|
||||
seq(kw("as"), $._list_of_identifiers),
|
||||
)),
|
||||
),
|
||||
|
||||
join_item: $ => choice(
|
||||
seq(kw("natural"), $.join_type, $.from_table),
|
||||
seq($.join_type, $.from_table, $.join_condition),
|
||||
seq(kw("cross"), kw("join"), $.from_table)
|
||||
),
|
||||
join_condition: $ => choice(
|
||||
seq(kw("on"), $._value_expression),
|
||||
seq(kw("using"), $._list_of_identifiers)
|
||||
),
|
||||
join_type: $ => seq(
|
||||
choice(
|
||||
optional(kw("inner")),
|
||||
seq(kw("left"), optional(kw("outer"))),
|
||||
seq(kw("right"), optional(kw("outer"))),
|
||||
seq(kw("full"), optional(kw("outer"))),
|
||||
),
|
||||
kw("join")
|
||||
),
|
||||
|
||||
create_function_statement: $ => seq(
|
||||
kw("CREATE"), optional($.or_replace), kw("FUNCTION"),
|
||||
kw("create"), optional($.or_replace), kw("function"),
|
||||
$.function_signature,
|
||||
optional(seq(kw("RETURNS"), $.identifier)),
|
||||
kw("AS"), $.block,
|
||||
kw("LANGUAGE"), $.identifier,
|
||||
$.function_return,
|
||||
kw("as"), choice(
|
||||
$.block,
|
||||
$.string,
|
||||
),
|
||||
kw("language"), choice($.identifier, $.string),
|
||||
optional($.function_volatility)
|
||||
),
|
||||
|
||||
function_return: $ => seq(
|
||||
kw("returns"),
|
||||
choice(
|
||||
$.identifier,
|
||||
$.return_setof,
|
||||
$.return_table,
|
||||
),
|
||||
),
|
||||
return_setof: $ => seq(kw("setof"), $.identifier),
|
||||
return_table: $ => seq(kw("table"), "(", commaSep1($.var_declaration), ")"),
|
||||
|
||||
function_volatility: $ => choice(
|
||||
kw("IMMUTABLE"),
|
||||
kw("STABLE"),
|
||||
kw("VOLATILE"),
|
||||
kw("immutable"),
|
||||
kw("stable"),
|
||||
kw("volatile"),
|
||||
),
|
||||
|
||||
block: $ => seq(
|
||||
$.dollar_quote,
|
||||
repeat($.declarations),
|
||||
$.body,
|
||||
$.dollar_quote,
|
||||
),
|
||||
|
||||
dollar_quote: $ => delimited("$", optional($.identifier)),
|
||||
body: $ => seq(
|
||||
kw("begin"),
|
||||
repeat($._plpgsql_statement),
|
||||
kw("end"),
|
||||
optional(";"),
|
||||
),
|
||||
|
||||
dollar_quote: $ => seq("$", optional($.identifier), "$"),
|
||||
|
||||
declarations: $ => seq(
|
||||
kw("declare"),
|
||||
repeat($.var_definition),
|
||||
),
|
||||
|
||||
var_definition: $ => seq(
|
||||
$.var_declaration,
|
||||
optional(seq(":=", $._value_expression)),
|
||||
";",
|
||||
),
|
||||
|
||||
function_signature: $ => seq(
|
||||
$.identifier,
|
||||
|
@ -62,22 +551,144 @@ module.exports = grammar({
|
|||
|
||||
function_parameters: $ => seq(
|
||||
"(",
|
||||
separated(",", $.function_parameter),
|
||||
commaSep($.var_declaration),
|
||||
optional(seq(kw("default"), field("default_value", ($._value_expression)))),
|
||||
")"
|
||||
),
|
||||
|
||||
function_parameter: $ => seq(
|
||||
var_declaration: $ => seq(
|
||||
field("name", $.identifier),
|
||||
field("type", $._type),
|
||||
),
|
||||
|
||||
or_replace: $ => seq("OR", "REPLACE"),
|
||||
where_filter: $ => seq(kw("where"), $._value_expression),
|
||||
or_replace: $ => seq(kw("or"), kw("replace")),
|
||||
temporary: $ => choice(kw("temp"), kw("temporary")),
|
||||
if_not_exists: $ => seq(kw("if"), kw("not"), kw("exists")),
|
||||
if_exists: $ => seq(kw("if"), kw("exists")),
|
||||
as: $ => seq(kw("as"), $.identifier),
|
||||
|
||||
_type: $ => choice(
|
||||
$.predefined_types,
|
||||
$.identifier,
|
||||
seq($._type, "[", "]"),
|
||||
),
|
||||
|
||||
// predefined_type:
|
||||
// | BIGINT { BigInt }
|
||||
// | BIT VARYING? l = type_length? { BitVarying(l) }
|
||||
// | BOOLEAN { Boolean }
|
||||
// | CHAR VARYING? l = type_length? { Char(l) }
|
||||
// | CHARACTER VARYING? l = type_length? { Char(l) }
|
||||
// | DEC p = precision_param? { Dec(p) }
|
||||
// | DECIMAL p = precision_param? { Decimal(p) }
|
||||
// | DOUBLE PRECISION { Double }
|
||||
// | FLOAT p = precision_param? { Float(p) }
|
||||
// | INT { Int }
|
||||
// | INTEGER { Integer }
|
||||
// | INTERVAL interval = interval_field? l = type_length? { Interval(interval, l) }
|
||||
// | NCHAR VARYING? l = type_length? { Nchar(l) }
|
||||
// | NUMERIC p = precision_param? { Numeric(p) }
|
||||
// | REAL { Real }
|
||||
// | SMALLINT { SmallInt }
|
||||
// | TEXT { Text }
|
||||
// (* | TIME l = type_length? (1* NOTE(chrde): what here? *1) *)
|
||||
// | TIME l = type_length? WITH TIME ZONE { TimeTz(l) }
|
||||
// | TIME l = type_length? WITHOUT TIME ZONE { Time(l) }
|
||||
// (* | TIMESTAMP l = type_length? (1* NOTE(chrde): what here? *1) *)
|
||||
// | TIMESTAMP l = type_length? WITH TIME ZONE { TimestampTz(l) }
|
||||
// | TIMESTAMPTZ l = type_length? { TimestampTz(l) }
|
||||
// | TIMESTAMP l = type_length? WITHOUT TIME ZONE { Timestamp(l) }
|
||||
// | VARCHAR l = type_length? { VarChar(l) }
|
||||
// (* | schema_qualified_name_nontype (LEFT_PAREN vex (COMMA vex)* RIGHT_PAREN)? *)
|
||||
// TODO(chrde): moar types!!
|
||||
predefined_types: $ => choice(
|
||||
seq(kw("numeric"), optional($.precision))
|
||||
),
|
||||
|
||||
precision: $ => seq("(", $.number, optional(seq(",", $.number)), ")"),
|
||||
|
||||
string: $ => seq(
|
||||
"'",
|
||||
repeat(choice(
|
||||
prec(1, /''/),
|
||||
prec(2, /[^']/),
|
||||
)),
|
||||
"'",
|
||||
),
|
||||
|
||||
// NOTE(chrde): taken from https://github.com/tree-sitter/tree-sitter-javascript/blob/1ddbf1588c353edab37791cdcc9f17e56fb4ea73/grammar.js#L899
|
||||
comment: $ => token(choice(
|
||||
seq('--', /.*/),
|
||||
seq(
|
||||
'/*',
|
||||
/[^*]*\*+([^/*][^*]*\*+)*/,
|
||||
'/'
|
||||
)
|
||||
)),
|
||||
|
||||
_value_expression: $ => choice(
|
||||
$.string,
|
||||
$.number,
|
||||
$.true,
|
||||
$.false,
|
||||
$.null,
|
||||
$.star,
|
||||
seq("(", $.select_statement, ")"),
|
||||
seq("(", $._value_expression, ")"),
|
||||
$.function_call,
|
||||
$.op_expression,
|
||||
$.time_expression,
|
||||
$.identifier,
|
||||
),
|
||||
|
||||
time_expression: $ => choice(
|
||||
seq($.identifier, kw("at"), kw("time"), kw("zone"), $._value_expression),
|
||||
),
|
||||
|
||||
function_call: $ => seq(
|
||||
$.identifier,
|
||||
"(",
|
||||
choice(
|
||||
$.select_statement,
|
||||
commaSep($._value_expression),
|
||||
),
|
||||
")"
|
||||
),
|
||||
|
||||
op_expression: $ => choice(
|
||||
prec.left(12, seq($._value_expression, $.cast, $._value_expression)),
|
||||
// array access
|
||||
prec.right(10, seq(choice($.minus, $.plus), $._value_expression)),
|
||||
// ^
|
||||
prec.left(8, seq($._value_expression, choice("*", "/", "%"), $._value_expression,)),
|
||||
prec.left(7, seq($._value_expression, choice("-", "+"), $._value_expression,)),
|
||||
prec.left(6, seq($._value_expression, $.other_op, $._value_expression)),
|
||||
// between in like ilike similar
|
||||
prec.left(4, seq($._value_expression, $.comparison_op, $._value_expression,)),
|
||||
// is isnull notnull
|
||||
prec.right(2, seq($.not, $._value_expression)),
|
||||
prec.left(1, seq($._value_expression, choice($.and, $.or), $._value_expression,)),
|
||||
),
|
||||
|
||||
_list_of_identifiers: $ => seq("(", commaSep($.identifier), ")"),
|
||||
|
||||
// TODO(chrde): https://www.postgresql.org/docs/13/sql-syntax-lexical.html
|
||||
comparison_op: $ => choice("<", ">", "=", "<=", ">=", "<>", "!="),
|
||||
// TODO(chrde): this should be a regex
|
||||
other_op: $ => choice("||"),
|
||||
cast: $ => "::",
|
||||
minus: $ => "-",
|
||||
plus: $ => "+",
|
||||
not: $ => kw("not"),
|
||||
and: $ => kw("and"),
|
||||
or: $ => kw("or"),
|
||||
true: $ => kw("true"),
|
||||
false: $ => kw("false"),
|
||||
null: $ => kw("null"),
|
||||
star: $ => "*",
|
||||
any: $ => /.*/,
|
||||
number: $ => /\d+/,
|
||||
identifier: $ => /[a-zA-Z0-9_]+[.a-zA-Z0-9_]*/,
|
||||
}
|
||||
});
|
||||
|
|
6619
src/grammar.json
6619
src/grammar.json
File diff suppressed because it is too large
Load diff
3599
src/node-types.json
3599
src/node-types.json
File diff suppressed because it is too large
Load diff
37223
src/parser.c
37223
src/parser.c
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue