Skip to content

feat(analysis): accept an aliased sole COUNT(*) projection - #32

Merged
omer-cengel merged 2 commits into
masterfrom
feature/scalar-count-projection
Sep 25, 2026
Merged

omer-cengel merged 2 commits into
masterfrom
feature/scalar-count-projection

Conversation

@omer-cengel

Copy link
Copy Markdown
Member

Summary

A read can now count its matching rows. When COUNT(*) with an alias is the only projection, the query generates a <QueryName>Result record with one non-null Long component named after the alias. Before this change, every COUNT(*) failed with Unsupported SELECT expression: Function, so a common CRUD count query could not be compiled.

Changes

  • Query analysis recognises an unqualified, case-insensitive COUNT(*) with an alias written with or without AS. It resolves as a non-null BIGINT column, which generates a Long component that is 0 when no row matches.
  • The count works with any supported source, predicate, ordering and pagination shape, and under any result annotation. Its predicate and pagination parameters bind as before.
  • COUNT(*) without an alias fails with COUNT(*) requires a result alias, such as COUNT(*) AS total.
  • COUNT(*) beside another projection item fails with COUNT(*) must be the only SELECT item.
  • New analyzer tests cover the accepted count and every rejected form. A new PostgreSQL integration test compiles a :one count, checks that its component is typed Long, and checks the result for matching and non-matching input.
  • The query reference documents the scalar count and its diagnostics. The quickstart's invalid-query example now uses a query that is still rejected.

Scope and non-goals

  • COUNT(column), COUNT(DISTINCT ...), COUNT(t.*), a qualified pg_catalog.count(*), the FILTER and OVER forms, and every other function or aggregate still fail with the existing unsupported-expression diagnostic.
  • GROUP BY and HAVING are still not analyzed, and RETURNING is unchanged.
  • The generator, the query model and the runtime are unchanged. An existing BIGINT result column already generates a Long component.

@omer-cengel
omer-cengel merged commit bd1233d into master Sep 25, 2026
6 checks passed
@omer-cengel
omer-cengel deleted the feature/scalar-count-projection branch September 25, 2026 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant