Skip to content

Commit

Permalink
Postgres frame_clause quoted interval (#4915)
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-finley authored Jun 12, 2023
1 parent 3762126 commit fe0c583
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/sqlfluff/dialects/dialect_ansi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,11 @@ class FrameClauseSegment(BaseSegment):
_frame_extent = OneOf(
Sequence("CURRENT", "ROW"),
Sequence(
OneOf(Ref("NumericLiteralSegment"), "UNBOUNDED"),
OneOf(
Ref("NumericLiteralSegment"),
Sequence("INTERVAL", Ref("QuotedLiteralSegment")),
"UNBOUNDED",
),
OneOf("PRECEDING", "FOLLOWING"),
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ from table_name;
SELECT rank () OVER (ORDER BY my_column RANGE BETWEEN 12 FOLLOWING AND CURRENT ROW EXCLUDE NO OTHERS);

SELECT rank () OVER (ORDER BY my_column GROUPS UNBOUNDED PRECEDING EXCLUDE GROUP);

SELECT rank () OVER (ORDER BY my_column RANGE BETWEEN
INTERVAL '1 YEAR - 1 DAYS' PRECEDING AND
INTERVAL '15 DAYS' PRECEDING);
35 changes: 34 additions & 1 deletion test/fixtures/dialects/postgres/postgres_select_frame_clause.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# computed by SQLFluff when running the tests. Please run
# `python test/generate_parse_fixture_yml.py` to generate them after adding or
# altering SQL files.
_hash: 18a34b63e1d4851cd20993a8a036d4662cd1313a9b56b741cf776f864948c85f
_hash: a2048f3f99a5a611fca4057c716cca3368f283650e74ae2d59125235ee04634e
file:
- statement:
select_statement:
Expand Down Expand Up @@ -133,3 +133,36 @@ file:
- keyword: GROUP
end_bracket: )
- statement_terminator: ;
- statement:
select_statement:
select_clause:
keyword: SELECT
select_clause_element:
function:
function_name:
function_name_identifier: rank
bracketed:
start_bracket: (
end_bracket: )
over_clause:
keyword: OVER
bracketed:
start_bracket: (
window_specification:
orderby_clause:
- keyword: ORDER
- keyword: BY
- column_reference:
naked_identifier: my_column
frame_clause:
- keyword: RANGE
- keyword: BETWEEN
- keyword: INTERVAL
- quoted_literal: "'1 YEAR - 1 DAYS'"
- keyword: PRECEDING
- keyword: AND
- keyword: INTERVAL
- quoted_literal: "'15 DAYS'"
- keyword: PRECEDING
end_bracket: )
- statement_terminator: ;

0 comments on commit fe0c583

Please sign in to comment.