Files
ems/db/routines/R__028_fn_modbus_written_command_ids.sql
2026-04-19 20:15:46 +02:00

21 lines
513 B
SQL

create or replace function ems.fn_modbus_written_command_ids(
p_site_id int,
p_lookback interval
)
returns jsonb
language sql
stable
as $fn$
select coalesce(
jsonb_agg(mc.id order by mc.written_at),
'[]'::jsonb
)
from ems.modbus_command mc
where mc.site_id = p_site_id
and mc.status = 'written'
and mc.written_at >= now() - p_lookback;
$fn$;
comment on function ems.fn_modbus_written_command_ids(int, interval) is
'ID written příkazů k ruční verifikaci (GET control/verify).';