Skip to content

Commit

Permalink
feat: add more options to pg views
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-Q committed Mar 19, 2023
1 parent d6963a2 commit 3cb1ee6
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 10 deletions.
46 changes: 36 additions & 10 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ module.exports = grammar({
keyword_high_priority: _ => make_keyword("high_priority"),
keyword_low_priority: _ => make_keyword("low_priority"),
keyword_delayed: _ => make_keyword("delayed"),
keyword_recursive: _ => make_keyword("recursive"),
keyword_cascaded: _ => make_keyword("cascaded"),
keyword_local: _ => make_keyword("local"),

// Hive Keywords
keyword_external: _ => make_keyword("external"),
Expand Down Expand Up @@ -222,6 +225,7 @@ module.exports = grammar({
_exclude_group: $ => seq($.keyword_exclude, $.keyword_group),
_exclude_no_others: $ => seq($.keyword_exclude, $.keyword_no, $.keyword_others),
_exclude_ties: $ => seq($.keyword_exclude, $.keyword_ties),
_check_option: $ => seq(make_keyword("check"), make_keyword("option")),
direction: $ => choice($.keyword_desc, $.keyword_asc),

// Types
Expand Down Expand Up @@ -644,19 +648,41 @@ module.exports = grammar({
),
),

create_view: $ => seq(
$.keyword_create,
optional($._or_replace),
$.keyword_view,
optional($._if_not_exists),
$.table_reference,
$.keyword_as,
choice(
create_view: $ => prec.right(
seq(
$.keyword_create,
optional($._or_replace),
optional($._temporary),
optional($.keyword_recursive),
$.keyword_view,
optional($._if_not_exists),
$.table_reference,
optional(paren_list($.identifier)),
$.keyword_as,
choice(
$._select_statement,
seq(
$._cte,
$._select_statement,
$._cte,
$._select_statement,
),
seq(
'(',
$._select_statement,
')',
),
),
optional(
seq(
$.keyword_with,
optional(
choice(
$.keyword_local,
$.keyword_cascaded,
)
),
$._check_option,
),
),
),
),

Expand Down
117 changes: 117 additions & 0 deletions test/corpus/create.txt
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,123 @@ SELECT * FROM my_table;
(table_reference
name: (identifier)))))))

================================================================================
Create temp view
================================================================================

CREATE TEMPORARY VIEW foo AS SELECT 1;
CREATE TEMP VIEW foo AS SELECT 1;

--------------------------------------------------------------------------------

(program
(statement
(create_view
(keyword_create)
(keyword_temporary)
(keyword_view)
(table_reference
(identifier))
(keyword_as)
(select
(keyword_select)
(select_expression
(term
(literal))))))
(statement
(create_view
(keyword_create)
(keyword_temp)
(keyword_view)
(table_reference
(identifier))
(keyword_as)
(select
(keyword_select)
(select_expression
(term
(literal)))))))

================================================================================
Create view with columns
================================================================================

CREATE VIEW foo(a, b) AS SELECT 1 a, 2 b;

--------------------------------------------------------------------------------

(program
(statement
(create_view
(keyword_create)
(keyword_view)
(table_reference
(identifier))
(identifier)
(identifier)
(keyword_as)
(select
(keyword_select)
(select_expression
(term
(literal)
(identifier))
(term
(literal)
(identifier)))))))

================================================================================
Create view with check option
================================================================================

CREATE VIEW foo AS SELECT 1 WITH CHECK OPTION;
CREATE VIEW foo AS SELECT 1 WITH LOCAL CHECK OPTION;
CREATE VIEW foo AS SELECT 1 WITH CASCADED CHECK OPTION;
--------------------------------------------------------------------------------

(program
(statement
(create_view
(keyword_create)
(keyword_view)
(table_reference
(identifier))
(keyword_as)
(select
(keyword_select)
(select_expression
(term
(literal))))
(keyword_with)))
(statement
(create_view
(keyword_create)
(keyword_view)
(table_reference
(identifier))
(keyword_as)
(select
(keyword_select)
(select_expression
(term
(literal))))
(keyword_with)
(keyword_local)))
(statement
(create_view
(keyword_create)
(keyword_view)
(table_reference
(identifier))
(keyword_as)
(select
(keyword_select)
(select_expression
(term
(literal))))
(keyword_with)
(keyword_cascaded))))

================================================================================
Create matview
================================================================================
Expand Down

0 comments on commit 3cb1ee6

Please sign in to comment.