sqlc-dev / sqlc

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

Typecast to nullable type #3698

Open quinn opened 1 week ago

quinn commented 1 week ago

What do you want to change?

            CASE
                WHEN t.amount = 0 THEN null
                ELSE t.price - t.amount
            END AS delta,

This gets typed as an empty interface.

            CASE
                WHEN t.amount = 0 THEN null
                ELSE (t.price - t.amount)::float
            END AS delta,

I get this error cannot scan NULL into *float64

This gets typed as a float64 when what I want is pgtype.Float8. Is there a workaround for this?

What database engines need to be changed?

PostgreSQL

What programming language backends need to be changed?

Go