Skip to content

Commit

Permalink
Added support for 'greater/less than or equal' on ANSI CASE statement (
Browse files Browse the repository at this point in the history
  • Loading branch information
IliyanKostov9 authored Apr 1, 2024
1 parent ae0a45f commit f400d6d
Show file tree
Hide file tree
Showing 3 changed files with 50 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 @@ -2000,7 +2000,11 @@ class CaseExpressionSegment(BaseSegment):
Dedent,
"END",
),
terminators=[Ref("CommaSegment"), Ref("BinaryOperatorGrammar")],
terminators=[
Ref("ComparisonOperatorGrammar"),
Ref("CommaSegment"),
Ref("BinaryOperatorGrammar"),
],
)


Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/dialects/ansi/select_case_c.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ select
else col3
end as text) as mycol
from table1;

SELECT
column1,
CASE
WHEN 'test' THEN 12
ELSE 0
END >= 0
FROM boo;
38 changes: 37 additions & 1 deletion test/fixtures/dialects/ansi/select_case_c.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: ea171e2218df3a613023d2a683870954ca0b9e3d75cc3dc5b42592f7fcf71db0
_hash: 87f657bcb3dc35a56ce876da187214ff201138c05fe2147c3cb79f78904d513e
file:
- statement:
select_statement:
Expand Down Expand Up @@ -139,3 +139,39 @@ file:
table_reference:
naked_identifier: table1
- statement_terminator: ;
- statement:
select_statement:
select_clause:
- keyword: SELECT
- select_clause_element:
column_reference:
naked_identifier: column1
- comma: ','
- select_clause_element:
expression:
case_expression:
- keyword: CASE
- when_clause:
- keyword: WHEN
- expression:
quoted_literal: "'test'"
- keyword: THEN
- expression:
numeric_literal: '12'
- else_clause:
keyword: ELSE
expression:
numeric_literal: '0'
- keyword: END
comparison_operator:
- raw_comparison_operator: '>'
- raw_comparison_operator: '='
numeric_literal: '0'
from_clause:
keyword: FROM
from_expression:
from_expression_element:
table_expression:
table_reference:
naked_identifier: boo
- statement_terminator: ;

0 comments on commit f400d6d

Please sign in to comment.