Skip to content

Instantly share code, notes, and snippets.

@artemholovnia
Last active May 30, 2023 09:44
Show Gist options
  • Save artemholovnia/11e698c6d1906a34644d72866e13156d to your computer and use it in GitHub Desktop.
Save artemholovnia/11e698c6d1906a34644d72866e13156d to your computer and use it in GitHub Desktop.
with cte as (
select ap.accounting_point_uid
-- s.parent_uid is null as "self_managed", s.*, '########', ap.indexed_data->'confirmed_at', ap.indexed_data->'canceled_at', ap.*
from artko.ms_processes_accountingpoint ap
, artko.ms_processes_subprocess s
where s.uid = ap.process_uid
and s.name in ('DISCONNECT_TKO')
and (
(s.parent_uid is null and s.started_at > '2023-05-10T15:00:00+00:00'::timestamptz and s.finished_at > '2023-05-10T15:00:00+00:00'::timestamptz)
or (s.parent_uid is not null and s.created_at > '2023-05-10T15:00:00+00:00'::timestamptz)
)
)
select ss.id, ss.name, ss.status, app.mp_id
from artko.ms_processes_subprocess s
, artko.ms_processes_subprocess ss
, unnest(s.tkos) ap
, cte
, artko.ms_tko_accountingpoint app
where s.name = 'CHANGE_SUPPLIER_TO_SUPPLIER'
and (s.additional_data ->> 'formed_at')::timestamptz > '2023-05-10T15:00:00+00:00'::timestamptz
and cte.accounting_point_uid = ap::uuid
and app.uid = ap::uuid
and ss.parent_uid = s.uid
and ss.name = 'INFORMING_AKO_FOR_CHANGE_SUPPLIER'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment