Skip to content

Conversation

@mkysel
Copy link
Collaborator

@mkysel mkysel commented Dec 18, 2025

The GetSecondNewestMinute query could return zero rows when no
“second newest” minute exists (e.g. fewer than two distinct minutes).
With a :one sqlc binding, this surfaced as sql: no rows in result set.

Rewrite the query to LEFT JOIN from a guaranteed single-row anchor,
ensuring the aggregate always has an input row. Missing data now
correctly yields (0, 0) via COALESCE instead of ErrNoRows.

This makes the query total and aligns its behavior with callers that
expect a result even when insufficient history exists.

@mkysel mkysel requested a review from a team as a code owner December 18, 2025 18:35
@mkysel
Copy link
Collaborator Author

mkysel commented Dec 18, 2025

Fixes #1467

@macroscopeapp
Copy link

macroscopeapp bot commented Dec 18, 2025

Use a LEFT JOIN for the second_newest_minute aggregation to return a single row with zeroed totals in payer report queries

Switch the second_newest_minute aggregation to an aliased LEFT JOIN on unsettled_usage with originator_id and minutes_since_epoch in the JOIN condition and update selected columns and aliases in payer_reports.sql and regenerated code in payer_reports.sql.go.

📍Where to Start

Start with the second_newest_minute aggregation query in payer_reports.sql, then review the generated changes in payer_reports.sql.go.


Macroscope summarized 94e7f5a.

@mkysel
Copy link
Collaborator Author

mkysel commented Dec 18, 2025

I need to double check that this works and write a unit test.

@mkysel mkysel marked this pull request as draft December 19, 2025 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants