feat: implicit VARCHAR-to-numeric cast for aggregate functions#326
Merged
tekumara merged 2 commits intotekumara:mainfrom Apr 11, 2026
Merged
Conversation
Snowflake implicitly casts VARCHAR columns to numeric when used in aggregate functions like SUM(), AVG(), MEDIAN(), etc. DuckDB is strict and rejects these with a BinderError. Add a numeric_agg_implicit_cast transform that wraps arguments to numeric-only aggregate functions with TRY_CAST(... AS DOUBLE), matching Snowflake's behavior. Only applies to SUM, AVG, MEDIAN, VARIANCE, STDDEV, etc. — not COUNT, MIN, MAX, ARRAY_AGG which work on any type.
tekumara
pushed a commit
that referenced
this pull request
Apr 11, 2026
🤖 I have created a release *beep* *boop* --- ## [0.11.5](v0.11.4...v0.11.5) (2026-04-11) ### Features * implicit VARCHAR-to-numeric cast for aggregate functions ([#326](#326)) ([3f47c30](3f47c30)) ### Bug Fixes * implicit VARCHAR-to-number cast matches snowflake column names ([5733c70](5733c70)) ### Chores * **deps-dev:** update snowflake-sqlalchemy requirement from ~=1.8.2 to ~=1.9.0 in the pip group across 1 directory ([#321](#321)) ([b8f4ede](b8f4ede)) * **deps:** update duckdb requirement from ~=1.4.1 to ~=1.5.1 ([#323](#323)) ([e8f49a0](e8f49a0)) * **deps:** update sqlglot requirement from ~=29.0.1 to ~=30.2.0 ([#322](#322)) ([3b434fa](3b434fa)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: potatobot-prime[bot] <132267321+potatobot-prime[bot]@users.noreply.github.com>
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.
Problem
Snowflake implicitly casts VARCHAR columns to numeric when used in aggregate functions like SUM(), AVG(), MEDIAN(), etc. DuckDB is strict and rejects these:
This is a common pattern when data is loaded via CSV (everything comes in as VARCHAR) and then aggregated without explicit casts.
Solution
Add a
numeric_agg_implicit_casttransform that wraps arguments to numeric-only aggregate functions withTRY_CAST(... AS DOUBLE), matching Snowflake's implicit coercion behavior.Example
Tests
test_transforms.pycovering SUM, AVG, COUNT (unchanged), MAX (unchanged), already-cast args, and mixed queriestest_fakes.pyverifying end-to-end SUM/AVG on a VARCHAR column