Skip to content

Commit

Permalink
feat(duckdb): Parse ** and ^ operators as POW (#4193)
Browse files Browse the repository at this point in the history
  • Loading branch information
VaggelisD authored Oct 1, 2024
1 parent 0388a51 commit 0adbbf7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sqlglot/dialects/duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ class Tokenizer(tokens.Tokenizer):
KEYWORDS = {
**tokens.Tokenizer.KEYWORDS,
"//": TokenType.DIV,
"**": TokenType.DSTAR,
"ATTACH": TokenType.COMMAND,
"BINARY": TokenType.VARBINARY,
"BITSTRING": TokenType.BIT,
Expand Down Expand Up @@ -325,6 +326,13 @@ class Parser(parser.Parser):
**parser.Parser.BITWISE,
TokenType.TILDA: exp.RegexpLike,
}
BITWISE.pop(TokenType.CARET)

EXPONENT = {
**parser.Parser.EXPONENT,
TokenType.CARET: exp.Pow,
TokenType.DSTAR: exp.Pow,
}

FUNCTIONS_WITH_ALIASED_ARGS = {*parser.Parser.FUNCTIONS_WITH_ALIASED_ARGS, "STRUCT_PACK"}

Expand Down
2 changes: 2 additions & 0 deletions tests/dialects/test_duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,8 @@ def test_duckdb(self):
"redshift": UnsupportedError,
},
)
self.validate_identity("a ^ b", "POWER(a, b)")
self.validate_identity("a ** b", "POWER(a, b)")

def test_array_index(self):
with self.assertLogs(helper_logger) as cm:
Expand Down

0 comments on commit 0adbbf7

Please sign in to comment.