Skip to content

Commit 3264deb

Browse files
feat(snowflake)!: Transpilation support for TO_DECIMAL, TO_NUMBER, TO_NUMERIC . 3.9 support. string concatenation ("\\" + c) instead of f-string interpolation
1 parent 563f533 commit 3264deb

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

sqlglot/dialects/duckdb.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4213,11 +4213,13 @@ def tonumber_sql(self, expression: exp.ToNumber) -> str:
42134213
chars = [c for symbol, c in chars_to_remove.items() if symbol in format_string]
42144214

42154215
if chars:
4216-
pattern = (
4217-
chars[0]
4218-
if len(chars) == 1
4219-
else f"[{''.join(c if c not in '.^$*+?{}[]\\|()' else f'\\{c}' for c in chars)}]"
4220-
)
4216+
if len(chars) == 1:
4217+
pattern = chars[0]
4218+
else:
4219+
# Escape special regex characters (Python 3.9 compatible)
4220+
regex_special = r".^$*+?{}[]\|()"
4221+
escaped = [c if c not in regex_special else "\\" + c for c in chars]
4222+
pattern = "[" + "".join(escaped) + "]"
42214223
this = exp.RegexpReplace(
42224224
this=this,
42234225
expression=exp.Literal.string(pattern),

0 commit comments

Comments
 (0)