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,24 @@
-- map register -> value_verified z modbus_command (poslední verified řádek per register)
create or replace function ems.fn_modbus_last_verified_map(
p_site_id int,
p_asset_id int
)
returns jsonb
language sql
stable
as $fn$
select coalesce(
jsonb_object_agg(register::text, to_jsonb(value_verified)),
'{}'::jsonb
)
from (
select
v.register,
v.value_verified
from ems.vw_modbus_last_verified v
where v.site_id = p_site_id
and v.asset_type = 'inverter'
and v.asset_id = p_asset_id
) t;
$fn$;