feat(duckdb): Add transpilation support for SUBSTR-SUBSTRING functions#7471
Merged
georgesittas merged 3 commits intomainfrom Apr 16, 2026
Merged
feat(duckdb): Add transpilation support for SUBSTR-SUBSTRING functions#7471georgesittas merged 3 commits intomainfrom
georgesittas merged 3 commits intomainfrom
Conversation
6c82dee to
771cfa0
Compare
Contributor
SQLGlot Integration Test ResultsComparing:
By Dialect
Overallmain: 109957 total, 108430 passed (pass rate: 98.6%), sqlglot version: sqlglot:RD-1147762-substr-substring: 106608 total, 105456 passed (pass rate: 98.9%), sqlglot version: Transitions: Dialect pair changes: 0 previous results not found, 1 curent results not found ✅ 23 test(s) passed |
1728111 to
0d33d57
Compare
georgesittas
requested changes
Apr 14, 2026
Comment on lines
+2512
to
+2525
| new_start = ( | ||
| exp.Literal.number(1) | ||
| if start is not None and start.is_number and start.to_py() == 0 | ||
| else exp.If(this=start.eq(0), true=exp.Literal.number(1), false=start.copy()) | ||
| if start is not None and not start.is_number | ||
| else None | ||
| ) | ||
| new_length = ( | ||
| exp.Literal.number(0) | ||
| if length is not None and length.is_number and length.to_py() < 0 | ||
| else exp.If(this=length.copy() < 0, true=exp.Literal.number(0), false=length.copy()) | ||
| if length is not None and not length.is_number | ||
| else None | ||
| ) |
Collaborator
There was a problem hiding this comment.
We should not handle literals manually. It results in more complicated logic and sets a precedent that we don't want to follow. Let's refactor these to always inject the If node in this branch.
| ) | ||
|
|
||
| if new_start is not None or new_length is not None: | ||
| expression = expression.copy() |
Collaborator
There was a problem hiding this comment.
We should not copy here. The generator already does this for you.
0d33d57 to
ae5603e
Compare
ae5603e to
9ddccff
Compare
georgesittas
approved these changes
Apr 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR aims to resolve the following issues:
Issue 1 — Zero start position
Snowflake
SUBSTR(str, 0, n)treats 0 as 1. DuckDB returns a shorter string. Fix: clamp 0 → 1.Issue 2 — Negative length
Snowflake
SUBSTR(str, pos, -n)returns ''. DuckDB silently returns wrong data. Fix: clamp negative → 0.