нужно исправить код: public.test_mv_incident_report_monitor as SELECT i.id, i.rule_id, i.rule_group, i.uuser, i.created_at, i.priority, i.is_deals, i.is_blacklisted, CASE WHEN i.is_deals THEN min(b.dealdtime) ELSE min(osec.dtime) END AS incidentstartdtime, CASE WHEN i.is_deals THEN max(b.dealdtime) ELSE max(osec.dtime) END AS incidentenddtime, CASE WHEN i.is_deals THEN string_agg(DISTINCT b.ticker::text, ','::text) ELSE string_agg(DISTINCT osec.ticker::text, ','::text) END AS ticker, CASE WHEN i.is_deals THEN string_agg(DISTINCT b.business::text, ','::text) ELSE string_agg(DISTINCT osec.business::text, ','::text) END AS business, CASE WHEN i.is_deals THEN string_agg(DISTINCT b.counterparty::text, ','::text) ELSE string_agg(DISTINCT osec.counterparty::text, ','::text) END AS counterparty, CASE WHEN i.is_deals THEN string_agg(DISTINCT b.client::text, ','::text) ELSE string_agg(DISTINCT osec.client::text, ','::text) END AS client, CASE WHEN i.is_deals THEN string_agg(DISTINCT b.dealmode::text, ','::text) ELSE string_agg(DISTINCT osec.dealmode::text, ','::text) END AS dealmode, CASE WHEN i.is_deals THEN string_agg(DISTINCT b.dealtype::text, ','::text) ELSE string_agg(DISTINCT osec.dealtype::text, ','::text) END AS dealtype, CASE WHEN i.is_deals THEN string_agg(DISTINCT b.desk::text, ','::text) ELSE ''::text END AS desk, CASE WHEN i.is_deals THEN string_agg(DISTINCT b.entity::text, ','::text) ELSE ''::text END AS entity, CASE WHEN i.is_deals THEN string_agg(DISTINCT b.location::text, ','::text) ELSE string_agg(DISTINCT osec.placement_location::text, ','::text) END AS location, CASE WHEN i.is_deals THEN string_agg(DISTINCT b.portfolio::text, ','::text) ELSE ''::text END AS portfolio, CASE WHEN i.is_deals THEN string_agg(DISTINCT b.salesteam::text, ','::text) ELSE ''::text END AS sales_team, CASE WHEN i.is_deals THEN string_agg(DISTINCT b.trader::text, ','::text) ELSE string_agg(DISTINCT osec.trader::text, ','::text) END AS trader, CASE WHEN i.is_deals THEN string_agg(DISTINCT b.user_id::text, ','::text) ELSE string_agg(DISTINCT osec.user_id::text, ','::text) END AS "user", CASE WHEN i.is_deals THEN string_agg(DISTINCT b.venue::text, ','::text) ELSE string_agg(DISTINCT osec.venue::text, ','::text) END AS venue, string_agg(DISTINCT ri.asset_class::text, ','::text) AS asset_class, string_agg(DISTINCT ri.business_line::text, ','::text) AS business_line, oa.job_id AS jobid, i.financial_result_rub, i.financial_result_usd, i.financial_result_eur, i.financial_result_cny, rr.rule_name, i.mode_incident, rr.is_archived, CASE WHEN i.is_deals THEN string_agg(DISTINCT b.middleoffice::text, ','::text) ELSE string_agg(DISTINCT osec.middle_office::text, ','::text) END AS middle_office, CASE WHEN i.is_deals THEN string_agg(DISTINCT b.back_office::text, ','::text) ELSE string_agg(DISTINCT osec.back_office::text, ','::text) END AS back_office FROM operation_audit oa JOIN incident_monitor i ON oa.tafs_id = i.id AND oa.entity_type::text = 'INCIDENT_MONITOR'::text LEFT JOIN incident_monitor_deals d ON i.id = d.incident_id AND d.check_orders = false LEFT JOIN deals_import b ON b.id = d.deal_id LEFT JOIN incident_monitor_orders io ON i.id = io.incident_id AND io.check_deals = false LEFT JOIN orders_import osec ON osec.id = io.order_id LEFT JOIN ref_issues ri ON ri.ticker::text = b.ticker::text AND ri.venue::text = b.venue::text OR ri.ticker::text = osec.ticker::text AND ri.venue::text = osec.venue::text AND ri.active LEFT JOIN ref_rules rr ON i.rule_id::text = rr.rule_id::text GROUP BY i.id, i.rule_id, i.rule_group, i.uuser, i.created_at, i.priority, i.is_deals, i.is_blacklisted, oa.job_id, rr.rule_name, rr.is_archived; alter materialized view public.test_mv_incident_report_monitor owner to ap; так, чтобы добавилось поле watchlist, в котором выводились name из таблицы watch_list_ref_counterparty ( id uuid not null constraint watch_list_ref_counterparty_pk primary key, name varchar, ref_counterparty_id_list varchar, count_incidents_without_status integer, count_incidents_with_status integer ); для клиентов, в которых они участвуют