Render aggregates over expressions (e.g. sumBy(caseWhen …)) instead of throwing#132
Merged
JordanMarr merged 1 commit intoJun 10, 2026
Conversation
…r throws AggregateColumn/NAggregateColumn threw "Invalid argument to aggregate function" whenever an aggregate's argument was not a bare column. This contradicted NAggregateColumn's own doc comment, which states that aggregates over arbitrary expressions should fall through to expression rendering. The throw broke valid conditional-aggregate queries such as SUM(CASE WHEN ... THEN 1 ELSE 0 END). Return None instead so the expression falls through to full rendering. The Option/Nullable .Value chain is already handled by the Property arm. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Owner
let sql =
select {
for p in production.product do
groupBy p.color
select (sumBy (caseWhen (p.standardcost > 100m) 1 0))
}
|> toSqlThat select statement is doing some work lol |
michaelglass
added a commit
to michaelglass/SqlHydra.Query.Pgvector
that referenced
this pull request
Jun 11, 2026
…n fix, JordanMarr/SqlHydra#132) Also bump test/dev dependencies to latest: Npgsql 9.0.4 -> 10.0.3, Microsoft.Testing.Extensions.CodeCoverage 18.5.2 -> 18.8.0, dotnet-fsharplint 0.26.10 -> 0.27.0, fsdocs-tool 21.0.0 -> 22.1.0, coverageratchet alpha.6 -> alpha.7.
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.
whoops, one more bug from me...
sumBy/avgBy/etc. over anything other than a bare column threwInvalid argument to aggregate function— even thoughNAggregateColumn's own doc comment says such expressions should fall through to full expression rendering. So a conditional count likeSUM(CASE WHEN … THEN 1 ELSE 0 END)was impossible.AggregateColumn/NAggregateColumnnow returnNonefor a non-column argument, letting it render as an expression. The Option/Nullable.Valuechain is unaffected — it's still matched by thePropertyarm.Tests:
sumBy/avgByovercaseWhennow renderSUM(CASE WHEN …)/AVG(CASE WHEN …).