sqlc-dev / sqlc

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

The sum of lengths becomes a float instead of an int. #3331

Open mondy opened 7 months ago

mondy commented 7 months ago

Version

1.26.0

What happened?

Input:

-- name: GetSize :one
SELECT sum(length(data)) FROM authors;

Output:

func (q *Queries) GetSize(ctx context.Context) (sql.NullFloat64, error) {
    row := q.db.QueryRowContext(ctx, getSize)
    var sum sql.NullFloat64
    err := row.Scan(&sum)
    return sum, err
}

Shouldn't the output NullFloat64 become NullInt64?

Relevant log output

No response

Database schema

CREATE TABLE authors (
  data BLOB NOT NULL
);

SQL queries

-- name: GetSize :one
SELECT sum(length(data)) FROM authors;

Configuration

{
  "version": "2",
  "sql": [{
    "schema": "schema.sql",
    "queries": "query.sql",
    "engine": "sqlite",
    "gen": {
      "go": {
        "out": "db"
      }
    }
  }]
}

Playground URL

https://play.sqlc.dev/p/66dd776b0c5aac077388f94ebc16d73088d78b36d0b8218113683aa13a371687

What operating system are you using?

Windows

What database engines are you using?

SQLite

What type of code are you generating?

Go

mondy commented 7 months ago

Related to #3122.