Skip to content

Commit c0b3448

Browse files
authored
feat(duckdb)!: parse at sign as ABS function (#4915)
1 parent 2fbbf6a commit c0b3448

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

sqlglot/dialects/duckdb.py

+1
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ class Parser(parser.Parser):
439439
NO_PAREN_FUNCTION_PARSERS = {
440440
**parser.Parser.NO_PAREN_FUNCTION_PARSERS,
441441
"MAP": lambda self: self._parse_map(),
442+
"@": lambda self: exp.Abs(this=self._parse_bitwise()),
442443
}
443444

444445
TABLE_ALIAS_TOKENS = parser.Parser.TABLE_ALIAS_TOKENS - {

tests/dialects/test_duckdb.py

+26
Original file line numberDiff line numberDiff line change
@@ -1569,3 +1569,29 @@ def test_prefix_aliases(self):
15691569
""",
15701570
"SELECT l_returnflag, l_linestatus, SUM(l_quantity) AS sum_qty, SUM(l_extendedprice) AS sum_base_price, SUM(l_extendedprice * (1 - l_discount)) AS sum_disc_price, SUM(l_extendedprice * (1 - l_discount) * (1 + l_tax)) AS sum_charge, AVG(l_quantity) AS avg_qty, AVG(l_extendedprice) AS avg_price, AVG(l_discount) AS avg_disc, COUNT(*) AS count_order",
15711571
)
1572+
1573+
def test_at_sign_to_abs(self):
1574+
self.validate_identity(
1575+
"SELECT @col FROM t",
1576+
"SELECT ABS(col) FROM t",
1577+
)
1578+
self.validate_identity(
1579+
"SELECT @col + 1 FROM t",
1580+
"SELECT ABS(col + 1) FROM t",
1581+
)
1582+
self.validate_identity(
1583+
"SELECT (@col) + 1 FROM t",
1584+
"SELECT (ABS(col)) + 1 FROM t",
1585+
)
1586+
self.validate_identity(
1587+
"SELECT @(-1)",
1588+
"SELECT ABS((-1))",
1589+
)
1590+
self.validate_identity(
1591+
"SELECT @(-1) + 1",
1592+
"SELECT ABS((-1) + 1)",
1593+
)
1594+
self.validate_identity(
1595+
"SELECT (@-1) + 1",
1596+
"SELECT (ABS(-1)) + 1",
1597+
)

0 commit comments

Comments
 (0)