Skip to content
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

Add a way to tell sqlc to always use nullable type when casting #3782

Open
quinn opened this issue Jan 12, 2025 · 1 comment
Open

Add a way to tell sqlc to always use nullable type when casting #3782

quinn opened this issue Jan 12, 2025 · 1 comment

Comments

@quinn
Copy link

quinn commented Jan 12, 2025

What do you want to change?

for example:

select null::float8 is a pgtype.Float8. However,

    select CASE WHEN true THEN null
    ELSE 0 END::float8,

is a float64. I'm basically having to do a bunch of weird stuff in sql to get sqlc to give up and codegen an interface{}, which sucks, but at least does not panic. And then I cast it at runtime to the correct type.

What database engines need to be changed?

PostgreSQL

What programming language backends need to be changed?

Go

@quinn quinn added the enhancement New feature or request label Jan 12, 2025
@snowtoslow
Copy link

snowtoslow commented Jan 16, 2025

Hey sir @quinn

In your sqlc.yaml/yml/json file you can add:

      go:
        #other config ommited for brievity
        overrides:
          - db_type: "float8"
            # nullable: true => should not be set, because it causes generation of `float64` idk why btw
            go_type:
              import: 'github.com/jackc/pgx/v5/pgtype'
              type: 'Float8'

Run sqlc generate. Should work 🙈

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

2 participants