drop type, open cursor

This commit is contained in:
Christian De la Hoz 2021-09-02 20:45:19 +02:00
parent 7beede0306
commit 931b7ab582
3 changed files with 107 additions and 0 deletions

View file

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

View file

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

View file

@ -46,6 +46,7 @@ module.exports = grammar({
$.psql_statement, $.psql_statement,
$.create_function_statement, $.create_function_statement,
$.drop_function_statement, $.drop_function_statement,
$.drop_type_statement,
$.create_table_statement, $.create_table_statement,
$.create_schema_statement, $.create_schema_statement,
$.create_type_statement, $.create_type_statement,
@ -61,6 +62,13 @@ module.exports = grammar({
$.do_block, $.do_block,
), ),
drop_type_statement: $ => seq(
kw("drop"), kw("type"),
optional($.if_exists),
commaSep1($.identifier),
optional(choice(kw("cascade"), kw("restrict")))
),
update_statement: $ => seq( update_statement: $ => seq(
optional($.with_query), optional($.with_query),
kw("update"), $.identifier, optional(seq(optional(kw("as")), $.identifier)), kw("update"), $.identifier, optional(seq(optional(kw("as")), $.identifier)),
@ -423,6 +431,7 @@ module.exports = grammar({
$._statement, $._statement,
$.assign_statement, $.assign_statement,
$.get_diagnostics_statement, $.get_diagnostics_statement,
$.open_cursor_statement,
$.return_statement, $.return_statement,
$.raise_statement, $.raise_statement,
$.if_statement, $.if_statement,
@ -433,6 +442,11 @@ module.exports = grammar({
";", ";",
), ),
open_cursor_statement: $ => seq(
kw("open"), $.identifier, kw("for"),
choice($.select_statement, $.execute_statement)
),
get_diagnostics_statement: $ => seq(kw("get"), optional(kw("current")), kw("diagnostics"), $.assign_statement), get_diagnostics_statement: $ => seq(kw("get"), optional(kw("current")), kw("diagnostics"), $.assign_statement),
for_statement: $ => seq( for_statement: $ => seq(