Repository navigation
feat(analysis): allow grouped counts and cast-typed projections - #58
Merged
Merged
Conversation
An aliased COUNT(*) may now stand beside other SELECT items as a non-null BIGINT column in its own position. A projection written as <expression>::type AS alias, or CAST(<expression> AS type) AS alias, becomes a nullable result column of the cast type, including declared enums and one-dimensional arrays. The cast operand is not analyzed and reaches the database as written; an unaliased cast and an unmapped cast type are rejected with their own diagnostics, and a projected placeholder stays rejected.
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.
Summary
Queries can now report grouped counts and computed values. An aliased
COUNT(*)may appear beside otherSELECTitems, soSELECT city, COUNT(*) AS venues ... GROUP BY citycompiles, and a projection whose type is stated by a cast, such asSUM(amount)::numeric AS total, becomes a typed result component.Changes
COUNT(*)is no longer required to be the onlySELECTitem; it is a non-nullLongcomponent in its own position beside direct columns, wildcards, cast projections, or other counts.<expression>::type AS aliasorCAST(<expression> AS type) AS alias(with or withoutAS) becomes a nullable component of the cast type, including declared enum types and one-dimensional arrays.A cast projection requires a result alias, such as SUM(amount)::numeric AS total.andResult column '<alias>' has unsupported cast type <TYPE>.SUM, including thenullresult when no row matches.docs/queries.mddocuments both projections, their diagnostics, and the covering tests.Scope and non-goals
GROUP BYandHAVINGremain unanalyzed and are passed through as written.COUNT(column),lower(name),FILTER/OVERforms) and row-type casts stay rejected as unsupportedSELECTexpressions.$1::int AS x, stays rejected.RETURNING, code generation, and the runtime are unchanged.