sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

Postgresql, sum of float turns into int

Open Jcambass opened this issue 7 months ago • 0 comments

Version

1.29.0

What happened?

The generated code uses an int64 despite the database column being a FLOAT.

Changing the engine to sqlite generates the correct code.

I suspected that sqlc detects the wrong postgres type in the first place since changing the query to SELECT CAST(SUM(length) as FLOAT) FROM foo; makes it work as expected.

Relevant log output


Database schema

CREATE TABLE foo (
  length FLOAT NOT NULL
);

SQL queries

-- name: Total :one
SELECT SUM(length) FROM foo;

Configuration

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

Playground URL

https://play.sqlc.dev/p/c334e3b188cf5aedbb0cfd252e75ecc3331fcb398a50e8880899a2a60e11a84c

What operating system are you using?

Mac

What database engines are you using?

postgresql

What type of code are you generating?

golang

Jcambass avatar May 15 '25 16:05 Jcambass