Загрузка данных


with tmp_dfa_status_priority as (
select 'preliminary_check' as status, 0 as priority union all
select 'modification', 1 union all
select 'issuer_confirmation', 2 union all
select 'teller_approval', 3 union all
select 'spec_approval', 4 union all
select 'lawyer_approval', 5 union all
select 'waiting_for_collection_started', 6 union all
select 'waiting_for_holding', 7 union all
select 'collection_started', 8 union all
select 'waiting_for_emitment', 9 union all
select 'waiting_for_emission', 10 union all
select 'emitment_success', 11 union all
select 'mature_preparation', 12 union all
select 'mature_confirmed', 13 union all
select 'waiting_for_mature', 14 union all
select 'mature', 15 union all
select 'redeemed', 16
)
update release_status_history h
   set dt_start_status = (
         select h.dt_start_status + make_interval(secs => p.priority)
           from tmp_dfa_status_priority p
          where p.status = h.status
       )
 where (h.ticker_symbol, h.dt_start_status) in (
         select ticker_symbol, dt_start_status
           from release_status_history
          group 
             by ticker_symbol, dt_start_status
         having count(*) > 1
       ) 
;