Skip to content

Overwrites do not work on query only fields #1346

@simonfrey

Description

@simonfrey

Version

1.11.0

What happened?

The types in a query are not overwritten. I want to overwrite the "real" type in the following query with a a sql.NullFloat64 in the go code.

The P75 is parsed into a go float32 field wich explodes if the value is NULL

type GetUrlLCPPercentilesRow struct {
	P75 float32
	One interface{}
}

func (q *Queries) GetUrlLCPPercentiles(ctx context.Context, arg GetUrlLCPPercentilesParams) (GetUrlLCPPercentilesRow, error) {
	row := q.db.QueryRowContext(ctx, getUrlLCPPercentiles, arg.Auth0id, arg.StartDate, arg.EndDate)
	var i GetUrlLCPPercentilesRow
	err := row.Scan(&i.P75, &i.One)
	return i, err
}

Now I tried to use an overwrite to get rid of this problem (see config below), but sadly the type of P75 is not adapted to sql.NullFloat64 as expected.

Relevant log output

No response

Database schema

No response

SQL queries

-- name: GetUrlLCPPercentiles :one
SELECT percentile_disc(0.75) WITHIN GROUP(ORDER BY lcp)::real P75, 1 as one
FROM event
WHERE lcp IS NOT NULL AND
        auth0id = $1 AND
        date(created_at) >= date(sqlc.arg(start_date)::date) AND date(created_at) <= date(sqlc.arg(end_date)::date);

Configuration

"version": "1"
"packages":
  - path: "internal/db/event"
    schema: "schema/"
    queries: "internal/db/event/sql/"
    engine: "postgresql"
  - path: "internal/db/account"
    schema: "schema/"
    queries: "internal/db/account/sql/"
    engine: "postgresql"
overrides:
  - db_type: "real"
    go_type: "database/sql.NullFloat64"
    nullable: true
  - db_type: "real"
    go_type: "database/sql.NullFloat64"
    nullable: false

Playground URL

No response

What operating system are you using?

Linux

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

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