Files
ems/db/routines/R__fn_ote_day_slot_stats_prague.sql
Dusan Vojacek 93f883f5e0
Some checks failed
CI and deploy / migration-check (push) Successful in 5s
CI and deploy / deploy (push) Failing after 20s
sql first refactor
2026-04-19 20:02:20 +02:00

43 lines
1.2 KiB
SQL

-- statistiky importovaných OTE slotů pro kalendářní den v Europe/Prague
create or replace function ems.fn_ote_day_slot_stats_prague(p_day date)
returns jsonb
language sql
stable
as $fn$
select jsonb_build_object(
'count',
coalesce(
(
select count(*)::int
from ems.market_interval_price mip
where mip.market_source = 'OTE_CZ'
and (mip.interval_start at time zone 'Europe/Prague')::date = p_day
),
0
),
'first_price',
(
select mip.buy_raw_price_czk_kwh
from ems.market_interval_price mip
where mip.market_source = 'OTE_CZ'
and (mip.interval_start at time zone 'Europe/Prague')::date = p_day
order by mip.interval_start
limit 1
),
'is_complete',
coalesce(
(
select count(*)::int
from ems.market_interval_price mip
where mip.market_source = 'OTE_CZ'
and (mip.interval_start at time zone 'Europe/Prague')::date = p_day
),
0
) in (92, 96, 100)
);
$fn$;
comment on function ems.fn_ote_day_slot_stats_prague(date) is
'Počet slotů OTE_CZ, první cena a zda den vypadá kompletně (92/96/100) v TZ Praha.';