Skip to content

Commit

Permalink
feat: add filter to aggregate_functions
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-Q committed Jun 28, 2023
1 parent ddd1763 commit 7a5ad78
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
11 changes: 11 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ module.exports = grammar({
keyword_as: _ => make_keyword("as"),
keyword_distinct: _ => make_keyword("distinct"),
keyword_constraint: _ => make_keyword("constraint"),
keyword_filter: _ => make_keyword("filter"),
keyword_cast: _ => make_keyword("cast"),
keyword_separator: _ => make_keyword("separator"),
keyword_max: _ => make_keyword("max"),
Expand Down Expand Up @@ -1927,6 +1928,13 @@ module.exports = grammar({
')',
),

filter_expression : $ => seq(
$.keyword_filter,
'(',
$.where,
')',
),

invocation: $ => prec(1,
seq(
$.object_reference,
Expand Down Expand Up @@ -1956,6 +1964,9 @@ module.exports = grammar({
')',
),
),
optional(
$.filter_expression
)
),
),

Expand Down
37 changes: 37 additions & 0 deletions test/corpus/select.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2668,3 +2668,40 @@ parenthesized select
(select_expression
(term
(literal))))))

================================================================================
Select with filtered aggregation
================================================================================

SELECT
count(*) FILTER (WHERE i < 5) AS filtered
FROM tab

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

(program
(statement
(select
(keyword_select)
(select_expression
(term
(invocation
(object_reference
(identifier))
(term
(all_fields))
(filter_expression
(keyword_filter)
(where
(keyword_where)
(binary_expression
(field
(identifier))
(literal)))))
(keyword_as)
(identifier))))
(from
(keyword_from)
(relation
(object_reference
(identifier))))))

0 comments on commit 7a5ad78

Please sign in to comment.