Skip to content

Commit 2073fdd

Browse files
committed
DuckDB uses SUBSTRING instead of SUBSTR
1 parent 23d2ad9 commit 2073fdd

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

sqlglot/dialects/duckdb.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def _build_capitalization_sql(
331331
) -> str:
332332
# empty string delimiter --> treat value as one word, no need to split
333333
if raw_delimiters_sql == "''":
334-
return f"UPPER(LEFT({value_to_split}, 1)) || LOWER(SUBSTR({value_to_split}, 2))"
334+
return f"UPPER(LEFT({value_to_split}, 1)) || LOWER(SUBSTRING({value_to_split}, 2))"
335335

336336
regex_ready_sql = escaped_delimiters_sql or raw_delimiters_sql
337337
delim_regex_sql = regex_ready_sql
@@ -351,14 +351,14 @@ def _build_capitalization_sql(
351351
self.func(
352352
"LIST_TRANSFORM",
353353
self.func("REGEXP_EXTRACT_ALL", value_to_split, split_regex_sql),
354-
"(seg, idx) -> CASE WHEN idx % 2 = 0 THEN UPPER(LEFT(seg, 1)) || LOWER(SUBSTR(seg, 2)) ELSE seg END",
354+
"(seg, idx) -> CASE WHEN idx % 2 = 0 THEN UPPER(LEFT(seg, 1)) || LOWER(SUBSTRING(seg, 2)) ELSE seg END",
355355
),
356356
)
357357
.else_(
358358
self.func(
359359
"LIST_TRANSFORM",
360360
self.func("REGEXP_EXTRACT_ALL", value_to_split, split_regex_sql),
361-
"(seg, idx) -> CASE WHEN idx % 2 = 1 THEN UPPER(LEFT(seg, 1)) || LOWER(SUBSTR(seg, 2)) ELSE seg END",
361+
"(seg, idx) -> CASE WHEN idx % 2 = 1 THEN UPPER(LEFT(seg, 1)) || LOWER(SUBSTRING(seg, 2)) ELSE seg END",
362362
),
363363
),
364364
"''",

tests/dialects/test_dialect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4373,7 +4373,7 @@ def duckdb_regex_literal_sql(delimiters: str) -> str:
43734373
with self.subTest(f"Testing DuckDB generation for {query} from {dialect}"):
43744374
self.assertEqual(
43754375
parse_one(query, read=dialect).sql("duckdb"),
4376-
"UPPER(LEFT(col, 1)) || LOWER(SUBSTR(col, 2))",
4376+
"UPPER(LEFT(col, 1)) || LOWER(SUBSTRING(col, 2))",
43774377
)
43784378

43794379
query = "INITCAP(col, NULL)"

0 commit comments

Comments
 (0)