Skip to content

Postgresql, sum of float turns into int #3966

Open
@Jcambass

Description

@Jcambass

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

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