fix(dark-tariff): allow report aggregate expressions in having and remove check_start lockout

This commit is contained in:
takuya committed 2026-11-29 13:37:45 +03:00
1 parent 25baa8fc2b
commit f07886c504
2 files changed
+18 -16

No files matched your search

@@ -124,6 +124,7 @@ declare
v_closed boolean;
v_word text;
v_num text;
v_agg_match text[];
v_types text[] := '{}';
v_vals text[] := '{}';
v_pos integer := 1;
@@ -191,6 +192,22 @@ begin
v_vals := array_append(v_vals, v_num);
v_i := v_i + length(v_num);
elsif v_ch ~ '^[A-Za-z_]$' then
if p_mode = 'having' then
v_agg_match := regexp_match(substr(p_expr, v_i), $re$^(sum\s*\(\s*\(\s*c\.data\s*->\s*'calculation'\s*->>\s*'(quantity|amount)'\s*\)\s*::\s*numeric\s*\))(?:\s|$|[=<>!)])$re$, 'i');
if v_agg_match is not null then
v_types := array_append(v_types, 'IDENT');
v_vals := array_append(v_vals, lower(v_agg_match[2]));
v_i := v_i + length(v_agg_match[1]);
continue;
end if;
v_agg_match := regexp_match(substr(p_expr, v_i), $re$^(count\s*\(\s*\*\s*\))(?:\s|$|[=<>!)])$re$, 'i');
if v_agg_match is not null then
v_types := array_append(v_types, 'IDENT');
v_vals := array_append(v_vals, 'readings');
v_i := v_i + length(v_agg_match[1]);
continue;
end if;
end if;
v_word := lower((regexp_match(substr(p_expr, v_i), '^([A-Za-z_][A-Za-z0-9_]*)'))[1]);
v_i := v_i + length(v_word);
if v_word in ('and', 'or', 'not') then