Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Count aggregate function is number | null, should be just number #191

Closed
golergka opened this issue Oct 7, 2020 · 1 comment
Closed
Labels
wontfix This will not be worked on

Comments

@golergka
Copy link
Contributor

golergka commented Oct 7, 2020

So, I have this straightforward query:

const someCountQuery = sql<ISomeCountQuery>`
	SELECT COUNT(*)::int AS count
	FROM someTable
	WHERE someCondition = TRUE

However, it's result type is:

export interface ISomeCountQuery {
	count: number | null
}

Shouldn't it just be number? Even if there are 0 rows satisfying the condition, the COUNT(*) aggregate function should be returning 0, not null.

@adelsz
Copy link
Owner

adelsz commented Nov 15, 2020

We rely on the Postgres type inference engine, and it looks like it returns a nullable integer type in this case. You can verify this by running a describe in the psql cli.
Going forward, I will be collecting a list of all such inconsistencies to see if someone on the Postgres team will be interested in fixing them at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants