Skip to content

Commit

Permalink
MySQL: Support DIV and MOD operators (#5879)
Browse files Browse the repository at this point in the history
  • Loading branch information
kzosabe committed May 14, 2024
1 parent 78af450 commit 5040383
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/sqlfluff/dialects/dialect_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@
Ref("VariableAssignmentSegment"),
]
),
ArithmeticBinaryOperatorGrammar=ansi_dialect.get_grammar(
"ArithmeticBinaryOperatorGrammar"
).copy(
insert=[
Ref("DivOperatorSegment"),
Ref("ModOperatorSegment"),
],
),
DateTimeLiteralGrammar=Sequence(
# MySQL does not require the keyword to be specified:
# https://dev.mysql.com/doc/refman/8.0/en/date-and-time-literals.html
Expand Down Expand Up @@ -291,6 +299,8 @@
CodeSegment,
type="system_variable",
),
DivOperatorSegment=StringParser("DIV", KeywordSegment, type="binary_operator"),
ModOperatorSegment=StringParser("MOD", KeywordSegment, type="binary_operator"),
DoubleQuotedJSONPath=TypedParser(
"double_quote",
CodeSegment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ SELECT 1 XOR 1;
SELECT 1 || 1;
SELECT col_1 && 1;
SELECT (col_1 = col_2) || col_3;
SELECT 5 DIV 2;
SELECT 5 MOD 2;
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: d21bd7c1927fa694dafe5d0812e99cabeeffb6fd21b122189c8c7dbb79328f70
_hash: 1cedf78417964649de92fb66c5035c6d7b5cf09c22b3f5b5232e2e233083c132
file:
- statement:
select_statement:
Expand Down Expand Up @@ -85,3 +85,23 @@ file:
column_reference:
naked_identifier: col_3
- statement_terminator: ;
- statement:
select_statement:
select_clause:
keyword: SELECT
select_clause_element:
expression:
- numeric_literal: '5'
- binary_operator: DIV
- numeric_literal: '2'
- statement_terminator: ;
- statement:
select_statement:
select_clause:
keyword: SELECT
select_clause_element:
expression:
- numeric_literal: '5'
- binary_operator: MOD
- numeric_literal: '2'
- statement_terminator: ;

0 comments on commit 5040383

Please sign in to comment.