sqlc-dev / sqlc

Generate type-safe code from SQL
https://sqlc.dev
MIT License
13.46k stars 805 forks source link

SUM() returns `interface{}` type for mysql #3579

Open meblum opened 2 months ago

meblum commented 2 months ago

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

curio77 commented 2 months ago

Same BTW for MAX() with PostgreSQL on an INTEGER-type column. Seems like a more general issue.

Jille commented 1 month ago

I had started on this a long time ago: https://github.com/sqlc-dev/sqlc/pull/3223

It wasn't trivial to fix sadly.