Description
Version
1.28.0
What happened?
I have the following query
-- name: Obtener_maximo :one
SELECT max(columna) from tabla;
[ columna in integer primary key in sqlite]
The generated code is like this
func (q *Queries) Obtener_maximo(ctx context.Context) (interface{}, error) {
row := q.db.QueryRowContext(ctx, obtener_maximo)
var max interface{}
err := row.Scan(&max)
return max, err
}
The problem with this code is that it returns a interface{} that can be of any type, which is useless. Instead, it should return an sql.NullInt64
It is enough to change the declaration of the max variable as
var max sql.NullInt64
A solution would be add an optional type to the query anotation like
-- name: Obtener_maximo :one sql.NullInt64
SELECT max(columna) from tabla;
to be used in the generated code.