feat(duckdb): Add transpilation support for COLLATION function#7443
Merged
georgesittas merged 2 commits intomainfrom Apr 6, 2026
Merged
feat(duckdb): Add transpilation support for COLLATION function#7443georgesittas merged 2 commits intomainfrom
georgesittas merged 2 commits intomainfrom
Conversation
georgesittas
requested changes
Apr 2, 2026
Comment on lines
+2965
to
+2971
| def collation_sql(self, expression: exp.Collation) -> str: | ||
| this = expression.this | ||
| if isinstance(this, exp.Collate) and this.expression.name: | ||
| return self.sql(this.expression) | ||
| self.unsupported("COLLATION function is not supported by DuckDB") | ||
| return self.sql(exp.null()) | ||
|
|
Collaborator
There was a problem hiding this comment.
@fivetran-amrutabhimsenayachit I don't think we should handle Collate as a special case. It's similar to why we don't want to handle NULL values explicitly. I wouldn't expect COLLATION(x COLLATE y) to show up in the wild, because that trivially evalutes to y.
I think we only want to call unsupported and do fallback_function_sql, not NULL.
40a9845 to
b8cfc52
Compare
Contributor
SQLGlot Integration Test ResultsComparing:
By Dialect
Overallmain: 110131 total, 108597 passed (pass rate: 98.6%), sqlglot version: sqlglot:RD-1147700-collation: 101221 total, 101221 passed (pass rate: 100.0%), sqlglot version: Transitions: ✅ 10 test(s) passed |
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.
DuckDB handles collation at the column-definition level via the
COLLATEclause, not as a queryable runtime function. There is no DuckDB equivalent that returns the collation specification of an expression.Fix:
E.g:
If there's an explicit
COLLATE'spec' attached and the spec is non-empty, the answer is already known at transpile time — so just write that spec as a plain string literal.Otherwise, there is no way to know the collation, so write NULL, which is exactly what Snowflake returns for uncollated expressions.