minor db merge queries#1374
Open
eranschweitzer wants to merge 2 commits into
Open
Conversation
1. in costs.py, `INSERT INTO results_project_costs_operations_agg` lists columns as `(... variable_om_cost, fuel_cost, ...)` but selects `SUM(fuel_cost) AS fuel_cost` first and `SUM(variable_om_cost) AS variable_om_cost` second. SQLite's INSERT is positional so the columns are stored swapped: the column named `variable_om_cost` actually holds period-aggregated fuel cost and vice versa. Reorder the SELECT to match the column list. 2. `results_project_costs_capacity_agg` writes `spinup_or_lookahead = 0` for non-spinup rows while `results_project_costs_operations_agg` (tx as well) write NULL, so the view's `a.spinup_or_lookahead = b.spinup_or_lookahead` join fails (NULL = 0 is UNKNOWN) and every operations / tx row is silently dropped. Wrap both sides in `COALESCE(..., 0)` so the condition is robust to either convention. 3. The 4th LEFT JOIN in `results_project_costs_capacity_agg` aliases `results_transmission_hurdle_costs_by_timepoint_agg` as `e` but its ON clause references `d.scenario_id` etc., so the join is effectively against the previous table again rather than the aliased one. Switch the references to `e.`. Issues found with help from Claude Opus 4.7.
Views `results_costs_by_period_load_zone` and `results_costs_by_period` aggregate by period and included either joins or summation over `results_transmission_hurdle_costs_by_timepoint_agg`. However, this view does not include period. This was silently ignored before and is now removed for clarity.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Minor SQL cost query fixes
results_project_costs_operations_agglists columns as (... variable_om_cost, fuel_cost, ...) but selects
SUM(fuel_cost) AS fuel_cost first and
SUM(variable_om_cost) AS variable_om_cost second. SQLite's INSERT
is positional so the columns are stored swapped: the column named
variable_om_cost actually holds period-aggregated fuel cost and
vice versa. Reorder the SELECT to match the column list.
results_project_costs_capacity_aggwritesspinup_or_lookahead = 0 for non-spinup rows while
results_project_costs_operations_agg (tx as well) write NULL,
so the view's a.spinup_or_lookahead = b.spinup_or_lookahead join
fails (NULL = 0 is UNKNOWN) and every operations / tx
row is silently dropped. These are wrapped in COALESCE(..., 0) so
the condition is robust to either convention.
results_costs_by_period_load_zoneand
results_costs_by_periodaggregate by period and includedeither joins or summation over
results_transmission_hurdle_costs_by_timepoint_agg.However, this view does not include period.
This was silently ignored before and is now removed for clarity.