sql first refactor
Some checks failed
CI and deploy / migration-check (push) Successful in 5s
CI and deploy / deploy (push) Failing after 20s

This commit is contained in:
Dusan Vojacek
2026-04-19 20:02:20 +02:00
parent a02e11ee13
commit 93f883f5e0
74 changed files with 6022 additions and 4014 deletions

View File

@@ -0,0 +1,23 @@
create or replace function ems.fn_latest_ote_day_stats()
returns jsonb
language sql
stable
as $fn$
select to_jsonb(sub)
from (
select
(mip.interval_start at time zone 'Europe/Prague')::date as latest_date,
count(*)::int as slots,
min(mip.buy_raw_price_czk_kwh)::float as min_price,
max(mip.buy_raw_price_czk_kwh)::float as max_price,
avg(mip.buy_raw_price_czk_kwh)::float as avg_price
from ems.market_interval_price mip
where mip.market_source in ('OTE_CZ', 'OTE_CZ_DAM')
group by (mip.interval_start at time zone 'Europe/Prague')::date
order by latest_date desc
limit 1
) sub;
$fn$;
comment on function ems.fn_latest_ote_day_stats() is
'Agregace posledního kalendářního dne s OTE daty (globální, bez site_id).';