Skip to content

Commit

Permalink
Add TOP to select clause modifiers for redshift dialect
Browse files Browse the repository at this point in the history
Fixes #3531
  • Loading branch information
pdebelak committed Jul 10, 2022
1 parent dc22a21 commit 0fffcae
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/sqlfluff/dialects/dialect_redshift.py
Expand Up @@ -2258,3 +2258,11 @@ class CallStatementSegment(BaseSegment):
"CALL",
Ref("FunctionSegment"),
)


class SelectClauseModifierSegment(postgres.SelectClauseModifierSegment):
"""Things that come after SELECT but before the columns."""

match_grammar = postgres.SelectClauseModifierSegment.match_grammar.copy(
insert=[Sequence("TOP", Ref("NumericLiteralSegment"))],
)
1 change: 1 addition & 0 deletions test/fixtures/dialects/redshift/select_top.sql
@@ -0,0 +1 @@
SELECT TOP 10 example_value_col FROM example_schema.some_table ORDER BY example_value_col;
32 changes: 32 additions & 0 deletions test/fixtures/dialects/redshift/select_top.yml
@@ -0,0 +1,32 @@
# YML test files are auto-generated from SQL files and should not be edited by
# hand. To help enforce this, the "hash" field in the file must match a hash
# 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: 894b302c1b6551a0d3ce2623548d2284bce4dc09e1b2b5cc3cd7bc3ec737b7e4
file:
statement:
select_statement:
select_clause:
keyword: SELECT
select_clause_modifier:
keyword: TOP
literal: '10'
select_clause_element:
column_reference:
identifier: example_value_col
from_clause:
keyword: FROM
from_expression:
from_expression_element:
table_expression:
table_reference:
- identifier: example_schema
- dot: .
- identifier: some_table
orderby_clause:
- keyword: ORDER
- keyword: BY
- column_reference:
identifier: example_value_col
statement_terminator: ;

0 comments on commit 0fffcae

Please sign in to comment.