SUM() returns `interface{}` type for mysql
Version
1.27.0
What happened?
Querying SELECT SUM(val) FROM authors will return interface{} instead if int
Relevant log output
No response
Database schema
CREATE TABLE authors (
val INT NOT NULL
);
SQL queries
-- name: GetSum :one
SELECT SUM(val) FROM authors;
Configuration
{
"version": "2",
"sql": [{
"schema": "schema.sql",
"queries": "query.sql",
"engine": "mysql",
"gen": {
"go": {
"out": "db"
}
}
}]
}
Playground URL
https://play.sqlc.dev/p/a38fb22db5ce7e2309fd44c197b20ade5e3b8f8f61085b8b39656ee651ff4ddf
What operating system are you using?
No response
What database engines are you using?
MySQL
What type of code are you generating?
Go
Same BTW for MAX() with PostgreSQL on an INTEGER-type column. Seems like a more general issue.
I had started on this a long time ago: https://github.com/sqlc-dev/sqlc/pull/3223
It wasn't trivial to fix sadly.
Looking forward to see #3223 completed and merged!
I'm not currently working on it. Feel free to fork.
Noted
The following workaround fixes this issue: SELECT 0 + SUM(val) FROM table; see in playground.
Originally posted by @sknig in #1965