Skip to content

Postgresql, sum of float turns into int #3966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Jcambass opened this issue May 15, 2025 · 0 comments
Open

Postgresql, sum of float turns into int #3966

Jcambass opened this issue May 15, 2025 · 0 comments

Comments

@Jcambass
Copy link

Jcambass commented May 15, 2025

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 Jcambass added the bug Something isn't working label May 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant