Description
Version
1.31.1
What happened?
NULLIF(a, b) is NULL when a = b, but sqlc reports its column as NOT NULL. With a database, the generated field is string, and scanning a row where the two are equal fails.
For the query below, with analyzer.database: true and a database.uri, I get:
type ListNamesRow struct {
ID int64
Name string
}I expected Name pgtype.Text. With no database the field is Name bool: that type is the old problem of #133, and it is not nullable either.
It is the same on main (3ad8b20). I found no existing issue: #133 and #1154 are about the type.
NULLIF parses as an A_Expr with a comparison operator, and outputColumns gives every comparison NotNull: true. Checking for A_Expr_Kind_NULLIF there fixes it: Bockit@12f9b2a. I can open a pull request if that is wanted.
The analysis was done with AI help and checked by me.
Relevant log output
No response
Database schema
CREATE TABLE depots (id BIGSERIAL PRIMARY KEY, name text NOT NULL);SQL queries
-- name: ListNames :many
SELECT d.id, nullif(d.name, 'unnamed') AS name FROM depots d;Configuration
version: "2"
sql:
- engine: postgresql
schema: schema.sql
queries: query.sql
gen:
go:
package: db
out: db
sql_package: pgx/v5Playground URL
No response
What operating system are you using?
macOS
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go
Activity