Skip to content

A select max(column) returns an interface{} which is useless! #3918

Closed
@pdenapo

Description

@pdenapo

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions