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

Overwrites do not work on query only fields #1346

Open
simonfrey opened this issue Dec 17, 2021 · 1 comment
Open

Overwrites do not work on query only fields #1346

simonfrey opened this issue Dec 17, 2021 · 1 comment

Comments

@simonfrey
Copy link

simonfrey commented Dec 17, 2021

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

@simonfrey simonfrey added bug Something isn't working triage New issues that hasn't been reviewed labels Dec 17, 2021
@simonfrey simonfrey changed the title Overwrites do not work on querie only fields Overwrites do not work on query only fields Dec 17, 2021
@kyleconroy kyleconroy added 📚 postgresql 💻 linux 🔧 golang and removed triage New issues that hasn't been reviewed labels Jan 26, 2022
@skabbes
Copy link
Contributor

skabbes commented Apr 2, 2022

Hey @simonfrey would my proposal for letting the developer control nullability at the query level help out here?

#1525

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

3 participants