This commit is contained in:
dheepa
2021-10-28 09:12:13 +00:00
parent f3cf5e1d2d
commit 8402c9b738
74 changed files with 3883 additions and 908 deletions

View File

@@ -13,6 +13,19 @@ CREATE OR REPLACE FUNCTION fw_core.fn_run_master_wrapper(p_client_id int,p_funct
w_client_id int := p_client_id;
begin
/****************************************************************
******* ForeWarn Licensing and / or usage Terms and Conditions ******
ForeWarn. The NextGen Insights Solution Platform
Copyright 2021 COMPEGENCE. All Rights Reserved
ForeWarn is a product of COMPEGENCE.
To be used only with a valid license from COMPEGENCE
www.compegence.com info@compegence.com
****************************************************************/
-- update fw_core.fw_jobctl_runschedule_jobstep set begin_status='started',start_time=now() where job_id = w_job_id and step_id = w_step_id and latest_runschedule_flag = '1';
for f in select distinct file_syspk,file_mnemonic,file_sheet_mnemonic,sheet_id
@@ -104,8 +117,11 @@ end if;
err_file_syspk := f.file_syspk;
continue;
end if;
perform archive.fn_run_block_archive(w_client_id, w_function_id);
perform archive.fn_run_block_archive(w_client_id, w_function_id,f.file_mnemonic);
--run transactional scripts depending on sheet mnemonic
if f.file_sheet_mnemonic = 'FTDRY_TRS' then
@@ -172,6 +188,10 @@ perform archive.fn_run_block_archive(w_client_id, w_function_id);
perform fw_core.fn_get_function_exception('staging2.fn_IHTBTD_BTD_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')');
else perform fw_core.fn_insert_db_error ( w_client_id, w_function_id, 1001, 'Compegence', f.file_syspk ,f.file_mnemonic, f.file_sheet_mnemonic ,null,'TRX wrapper', 'unknown TRX', null, 'no script found', null, null, null,'error');
end if;
perform fw_core.fn_get_function_exception('transactional.fn_run_updates('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')');
-- check if transactional script ran correctly and update fw_jobctl_file_sheet_runschedule table.
select e.status from fw_core.db_run_status e where file_syspk = f.file_syspk and file_sheet_mnemonic =f.file_sheet_mnemonic and staging_type = 'trx' order by error_timestamp desc into TRX_status;
if TRX_status = 'success' then
@@ -190,16 +210,20 @@ end if;
end loop;
perform transactional.fn_run_updates(w_client_id, w_function_id);
--perform transactional.fn_run_updates(w_client_id, w_function_id,f.file_syspk);
--perform fw_core.fn_get_function_exception('transactional.fn_run_updates('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')');
-- update fw_jobctl_file_runschedule table.
update fw_core.fw_jobctl_file_runschedule set end_status_note = 'stg2_failed', end_status='error',staging_type = 'stg2',end_time=now() from fw_core.fw_jobctl_file_sheet_runschedule a
where a.latest_runschedule_flag = '1' and a.end_status = 'error' and a.end_status_note = 'stg2_failed' and fw_core.fw_jobctl_file_runschedule.file_syspk = a.file_syspk;
update fw_core.fw_jobctl_file_runschedule set end_status_note = 'TRX_completed', end_status='success',staging_type = 'trx',end_time=now() from fw_core.fw_jobctl_file_sheet_runschedule a
where a.latest_runschedule_flag = '1' and a.end_status = 'success' and a.end_status_note ='TRX_completed' and fw_core.fw_jobctl_file_runschedule.file_syspk = a.file_syspk;
update fw_core.fw_jobctl_file_runschedule set end_status_note = 'stg2_failed', end_status='error',staging_type = 'stg2',end_time=now() from fw_core.fw_jobctl_file_sheet_runschedule a
where a.latest_runschedule_flag = '1' and a.end_status = 'error' and a.end_status_note = 'stg2_failed' and fw_core.fw_jobctl_file_runschedule.file_syspk = a.file_syspk;
update fw_core.fw_jobctl_file_runschedule set end_status_note = 'TRX_failed', end_status='error',staging_type = 'trx' ,end_time=now() from fw_core.fw_jobctl_file_sheet_runschedule a
where a.latest_runschedule_flag = '1' and a.end_status = 'error' and a.end_status_note = 'TRX_failed' and fw_core.fw_jobctl_file_runschedule.file_syspk = a.file_syspk;
@@ -212,7 +236,5 @@ else
update fw_core.fw_jobctl_runschedule_jobstep set end_status_note = 'trx_failed', end_status='success', end_time=now() where job_id = w_job_id and step_id = w_step_id and latest_runschedule_flag = '1';
end if;
end;
$$ LANGUAGE plpgsql;

View File

@@ -1,163 +0,0 @@
CREATE OR REPLACE FUNCTION fw_ods.fn_fw_ods_load(p_client_id int,p_function_id int,p_job_id int,p_step_id int)
RETURNS void
AS $$
declare
f record;
w_job_id int := p_job_id;
w_step_id int := p_step_id;
w_function_id int := p_function_id;
w_client_id int := p_client_id;
w_file_sheet_mnemonic text := 'Sheets';
begin
for f in select distinct file_syspk, file_mnemonic
from fw_core.fw_jobctl_file_runschedule
where latest_runschedule_flag = '1' and
end_status = 'success' and
end_status_note = 'TRX_completed'
order by file_syspk
loop
if f.file_mnemonic in ('FTDRY', 'FTWET', 'FTHLG')
then
perform fw_core.fn_get_function_exception('fw_ods.fn_fw_ods_field_load('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||w_file_sheet_mnemonic||''','||f.file_syspk||')');
perform fw_core.fn_get_function_exception('fw_ods.fn_fw_ods_implement_details_update('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||w_file_sheet_mnemonic||''','||f.file_syspk||')');
perform fw_core.fn_get_function_exception('fw_ods.fn_fw_ods_comments_load('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||w_file_sheet_mnemonic||''','||f.file_syspk||')');
SET search_path To fw_ods;
drop extension tablefunc;
CREATE extension tablefunc;
perform fw_core.fn_get_function_exception('fw_ods.fn_fw_ods_observations_load('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||w_file_sheet_mnemonic||''','||f.file_syspk||')');
SET search_path To staging2;
drop extension tablefunc;
CREATE extension tablefunc;
elsif f.file_mnemonic ='PTO' then
perform fw_core.fn_get_function_exception('fw_ods.fn_fw_ods_PTO_load('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||w_file_sheet_mnemonic||''','||f.file_syspk||')');
elsif f.file_mnemonic = 'BUDNI' then
perform fw_core.fn_get_function_exception('fw_ods.fn_fw_ods_budni_load('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||w_file_sheet_mnemonic||''','||f.file_syspk||')');
elsif f.file_mnemonic in ('PTOBEN', 'PTOSTD') then
perform fw_core.fn_get_function_exception('fw_ods.fn_fw_ods_PTO_load('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||w_file_sheet_mnemonic||''','||f.file_syspk||')');
elsif f.file_mnemonic in ('IHTBT30','IHTBT50','IHTBTD','IHTCGM','IHTHAM','IHTEMT','IHTHLS','IHTNST','IHTSLL') then
perform fw_core.fn_get_function_exception('fw_ods.fn_fw_ods_IHT_load('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||w_file_sheet_mnemonic||''','||f.file_syspk||')');
perform fw_core.fn_get_function_exception('fw_ods.fn_fw_ods_detailed_load('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||w_file_sheet_mnemonic||''','||f.file_syspk||')');
elsif f.file_mnemonic in ('DBOECD', 'DBSTD') then
perform fw_core.fn_get_function_exception('fw_ods.fn_fw_ods_drawbar_performance_load('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||w_file_sheet_mnemonic||''','||f.file_syspk||')');
perform fw_core.fn_get_function_exception('fw_ods.fn_fw_ods_drawbar_load('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||w_file_sheet_mnemonic||''','||f.file_syspk||')');
end if;
end loop;
update fw_ods.fw_ods set tractor_model=REGEXP_REPLACE(tractor_model,'\r|\n','','g');
update fw_ods.fw_ods set tractor_make = m.target_value from fw_ods.fw_ods_misnomer m where trim(tractor_make) = m.source_value ;
update fw_ods.fw_ods set tractor_model = m.target_value from fw_ods.fw_ods_misnomer m where trim(tractor_model) = m.source_value ;
update fw_ods.fw_ods set wheel_drive_type = m.target_value from fw_ods.fw_ods_misnomer m where trim(wheel_drive_type) = m.source_value ;
update fw_ods.fw_ods set name_of_implement = m.target_value from fw_ods.fw_ods_misnomer m where trim(name_of_implement) = m.source_value ;
update fw_ods.fw_ods set type_of_implement = m.target_value from fw_ods.fw_ods_misnomer m where trim(type_of_implement) = m.source_value ;
update fw_ods.fw_ods set "configuration" = m."configuration",
tractor_engine_hp = m.tractor_engine_hp, wheel_drive_type=m.wheel_drive_type,platform = m.platform,tractor_make = m.tractor_make
from fw_ods.tractor_info m where fw_ods.fw_ods.tractor_model = m.tractor_model;
update fw_ods.fw_ods_comments set tractor_model=REGEXP_REPLACE(tractor_model,'\r|\n','','g');
update fw_ods.fw_ods_comments set tractor_make = m.target_value from fw_ods.fw_ods_misnomer m where trim(tractor_make) = m.source_value ;
update fw_ods.fw_ods_comments set tractor_model = m.target_value from fw_ods.fw_ods_misnomer m where trim(tractor_model) = m.source_value ;
update fw_ods.fw_ods_comments set wheel_drive_type = m.target_value from fw_ods.fw_ods_misnomer m where trim(wheel_drive_type) = m.source_value ;
update fw_ods.fw_ods_comments set name_of_implement = m.target_value from fw_ods.fw_ods_misnomer m where trim(name_of_implement) = m.source_value ;
update fw_ods.fw_ods_comments set type_of_implement = m.target_value from fw_ods.fw_ods_misnomer m where trim(type_of_implement) = m.source_value ;
update fw_ods.fw_ods_drawbar_performance set tractor_model=REGEXP_REPLACE(tractor_model,'\r|\n','','g');
update fw_ods.fw_ods_drawbar_performance set tractor_make = m.target_value from fw_ods.fw_ods_misnomer m where trim(tractor_make) = m.source_value ;
update fw_ods.fw_ods_drawbar_performance set tractor_model = m.target_value from fw_ods.fw_ods_misnomer m where trim(tractor_model) = m.source_value ;
update fw_ods.fw_ods_drawbar_performance set wheel_drive_type = m.target_value from fw_ods.fw_ods_misnomer m where trim(wheel_drive_type) = m.source_value ;
-- update fw_ods.fw_ods_drawbar_performance set name_of_implement = m.target_value from fw_ods.fw_ods_misnomer m where trim(name_of_implement) = m.source_value ;
--update fw_ods.fw_ods_drawbar_performance set type_of_implement = m.target_value from fw_ods.fw_ods_misnomer m where trim(type_of_implement) = m.source_value ;
update fw_ods.fw_ods_drawbar_performance set "configuration" = m."configuration",
tractor_engine_hp = m.tractor_engine_hp, wheel_drive_type=m.wheel_drive_type,platform = m.platform,tractor_make = m.tractor_make
from fw_ods.tractor_info m where fw_ods.fw_ods_drawbar_performance.tractor_model = m.tractor_model;
update fw_ods.fw_ods_comments set "configuration" = m."configuration",
tractor_engine_hp = m.tractor_engine_hp, wheel_drive_type=m.wheel_drive_type,platform = m.platform,tractor_make = m.tractor_make
from fw_ods.tractor_info m where fw_ods.fw_ods_comments.tractor_model = m.tractor_model;
update fw_ods.fw_ods_detailed set tractor_model=REGEXP_REPLACE(tractor_model,'\r|\n','','g');
update fw_ods.fw_ods_detailed set tractor_make = m.target_value from fw_ods.fw_ods_misnomer m where trim(tractor_make) = m.source_value ;
update fw_ods.fw_ods_detailed set tractor_model = m.target_value from fw_ods.fw_ods_misnomer m where trim(tractor_model) = m.source_value ;
update fw_ods.fw_ods_detailed set wheel_drive_type = m.target_value from fw_ods.fw_ods_misnomer m where trim(wheel_drive_type) = m.source_value ;
-- update fw_ods.fw_ods_detailed set name_of_implement = m.target_value from fw_ods.fw_ods_misnomer m where trim(name_of_implement) = m.source_value ;
--update fw_ods.fw_ods_detailed set type_of_implement = m.target_value from fw_ods.fw_ods_misnomer m where trim(type_of_implement) = m.source_value ;
update fw_ods.fw_ods_detailed set "configuration" = m."configuration",
tractor_engine_hp = m.tractor_engine_hp, wheel_drive_type=m.wheel_drive_type,platform = m.platform,tractor_make = m.tractor_make
from fw_ods.tractor_info m where fw_ods.fw_ods_detailed.tractor_model = m.tractor_model;
update fw_ods.fw_ods_observations set tractor_model=REGEXP_REPLACE(tractor_model,'\r|\n','','g');
update fw_ods.fw_ods_observations set tractor_make = m.target_value from fw_ods.fw_ods_misnomer m where trim(tractor_make) = m.source_value ;
update fw_ods.fw_ods_observations set tractor_model = m.target_value from fw_ods.fw_ods_misnomer m where trim(tractor_model) = m.source_value ;
update fw_ods.fw_ods_observations set wheel_drive_type = m.target_value from fw_ods.fw_ods_misnomer m where trim(wheel_drive_type) = m.source_value ;
update fw_ods.fw_ods_observations set name_of_implement = m.target_value from fw_ods.fw_ods_misnomer m where trim(name_of_implement) = m.source_value ;
update fw_ods.fw_ods_observations set type_of_implement = m.target_value from fw_ods.fw_ods_misnomer m where trim(type_of_implement) = m.source_value ;
update fw_ods.fw_ods_observations set "configuration" = m."configuration",
tractor_engine_hp = m.tractor_engine_hp, wheel_drive_type=m.wheel_drive_type,platform = m.platform,tractor_make = m.tractor_make
from fw_ods.tractor_info m where fw_ods.fw_ods_observations.tractor_model = m.tractor_model;
update fw_core.fw_jobctl_runschedule_jobstep set end_status_note = 'TRX_completed', end_status='success', end_time=now() where job_id = p_job_id and step_id = p_step_id and latest_runschedule_flag = '1';
end
$$
LANGUAGE plpgsql;

View File

@@ -1,66 +1,81 @@
drop function if exists staging2.fn_BUDNI_RUN;
CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_RUN()
RETURNS void AS $$
declare
f record;
w_file_syspk int;
status text;
begin
for f in select distinct a.file_syspk
from fw_core.fw_jobctl_file_runschedule a
where end_status like 'stg1-completed' and file_mnemonic='BUDNI'
loop
select f.file_syspk into w_file_syspk;
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_ARC_Block(20,1,''BUDNI'',''BUDNI_ARC'','||w_file_syspk||')');
select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_ARC' order by error_timestamp desc into status;
if status = 'success' then
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_ARC_TRX(20,1,''BUDNI'',''BUDNI_ARC'','||w_file_syspk||')');
end if;
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_BRK_Block (20,1,''BUDNI'',''BUDNI_BRK'','||w_file_syspk||')');
select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_BRK' order by error_timestamp desc into status;
if status = 'success' then
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_BRK_TRX(20,1,''BUDNI'',''BUDNI_BRK'','||w_file_syspk||')');
end if;
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_DBP_Block (20,1,''BUDNI'',''BUDNI_DBP'','||w_file_syspk||')');
select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_DBP' order by error_timestamp desc into status;
if status = 'success' then
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_DBP_TRX(20,1,''BUDNI'',''BUDNI_DBP'','||w_file_syspk||')');
end if;
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_FLD_Block (20,1,''BUDNI'',''BUDNI_FLD'','||w_file_syspk||')');
select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_FLD' order by error_timestamp desc into status;
if status = 'success' then
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_FLD_TRX(20,1,''BUDNI'',''BUDNI_FLD'','||w_file_syspk||')');
end if;
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_HDL_Block(20,1,''BUDNI'',''BUDNI_HDL'','||w_file_syspk||')');
select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_HDL' order by error_timestamp desc into status;
if status = 'success' then
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_HDL_TRX(20,1,''BUDNI'',''BUDNI_HDL'','||w_file_syspk||')');
end if;
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_HLG_Block(20,1,''BUDNI'',''BUDNI_HLG'','||w_file_syspk||')');
select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_HLG' order by error_timestamp desc into status;
if status = 'success' then
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_HLG_TRX(20,1,''BUDNI'',''BUDNI_HLG'','||w_file_syspk||')');
end if;
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_LCG_Block(20,1,''BUDNI'',''BUDNI_LCG'','||w_file_syspk||')');
select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_LCG' order by error_timestamp desc into status;
if status = 'success' then
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_LCG_TRX(20,1,''BUDNI'',''BUDNI_LCG'','||w_file_syspk||')');
end if;
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_NMT_Block(20,1,''BUDNI'',''BUDNI_NMT'','||w_file_syspk||')');
select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_NMT' order by error_timestamp desc into status;
if status = 'success' then
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_NMT_TRX(20,1,''BUDNI'',''BUDNI_NMT'','||w_file_syspk||')');
end if;
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_PTO_Block(20,1,''BUDNI'',''BUDNI_PTO'','||w_file_syspk||')');
select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_PTO' order by error_timestamp desc into status;
if status = 'success' then
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_PTO_TRX(20,1,''BUDNI'',''BUDNI_PTO'','||w_file_syspk||')');
end if;
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_VMT_Block(20,1,''BUDNI'',''BUDNI_VMT'','||w_file_syspk||')');
select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_VMT' order by error_timestamp desc into status;
if status = 'success' then
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_VMT_TRX(20,1,''BUDNI'',''BUDNI_VMT'','||w_file_syspk||')');
end if;
end loop;
end;
$$ LANGUAGE plpgsql;
drop function if exists staging2.fn_BUDNI_RUN;
CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_RUN()
RETURNS void AS $$
declare
f record;
w_file_syspk int;
status text;
begin
/****************************************************************
******* ForeWarn Licensing and / or usage Terms and Conditions ******
ForeWarn. The NextGen Insights Solution Platform
Copyright 2021 COMPEGENCE. All Rights Reserved
ForeWarn is a product of COMPEGENCE.
To be used only with a valid license from COMPEGENCE
www.compegence.com info@compegence.com
****************************************************************/
for f in select distinct a.file_syspk
from fw_core.fw_jobctl_file_runschedule a
where end_status like 'stg1-completed' and file_mnemonic='BUDNI'
loop
select f.file_syspk into w_file_syspk;
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_ARC_Block(20,1,''BUDNI'',''BUDNI_ARC'','||w_file_syspk||')');
select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_ARC' order by error_timestamp desc into status;
if status = 'success' then
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_ARC_TRX(20,1,''BUDNI'',''BUDNI_ARC'','||w_file_syspk||')');
end if;
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_BRK_Block (20,1,''BUDNI'',''BUDNI_BRK'','||w_file_syspk||')');
select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_BRK' order by error_timestamp desc into status;
if status = 'success' then
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_BRK_TRX(20,1,''BUDNI'',''BUDNI_BRK'','||w_file_syspk||')');
end if;
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_DBP_Block (20,1,''BUDNI'',''BUDNI_DBP'','||w_file_syspk||')');
select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_DBP' order by error_timestamp desc into status;
if status = 'success' then
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_DBP_TRX(20,1,''BUDNI'',''BUDNI_DBP'','||w_file_syspk||')');
end if;
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_FLD_Block (20,1,''BUDNI'',''BUDNI_FLD'','||w_file_syspk||')');
select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_FLD' order by error_timestamp desc into status;
if status = 'success' then
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_FLD_TRX(20,1,''BUDNI'',''BUDNI_FLD'','||w_file_syspk||')');
end if;
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_HDL_Block(20,1,''BUDNI'',''BUDNI_HDL'','||w_file_syspk||')');
select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_HDL' order by error_timestamp desc into status;
if status = 'success' then
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_HDL_TRX(20,1,''BUDNI'',''BUDNI_HDL'','||w_file_syspk||')');
end if;
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_HLG_Block(20,1,''BUDNI'',''BUDNI_HLG'','||w_file_syspk||')');
select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_HLG' order by error_timestamp desc into status;
if status = 'success' then
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_HLG_TRX(20,1,''BUDNI'',''BUDNI_HLG'','||w_file_syspk||')');
end if;
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_LCG_Block(20,1,''BUDNI'',''BUDNI_LCG'','||w_file_syspk||')');
select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_LCG' order by error_timestamp desc into status;
if status = 'success' then
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_LCG_TRX(20,1,''BUDNI'',''BUDNI_LCG'','||w_file_syspk||')');
end if;
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_NMT_Block(20,1,''BUDNI'',''BUDNI_NMT'','||w_file_syspk||')');
select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_NMT' order by error_timestamp desc into status;
if status = 'success' then
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_NMT_TRX(20,1,''BUDNI'',''BUDNI_NMT'','||w_file_syspk||')');
end if;
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_PTO_Block(20,1,''BUDNI'',''BUDNI_PTO'','||w_file_syspk||')');
select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_PTO' order by error_timestamp desc into status;
if status = 'success' then
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_PTO_TRX(20,1,''BUDNI'',''BUDNI_PTO'','||w_file_syspk||')');
end if;
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_VMT_Block(20,1,''BUDNI'',''BUDNI_VMT'','||w_file_syspk||')');
select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_VMT' order by error_timestamp desc into status;
if status = 'success' then
perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_VMT_TRX(20,1,''BUDNI'',''BUDNI_VMT'','||w_file_syspk||')');
end if;
end loop;
end;
$$ LANGUAGE plpgsql;

View File

@@ -1,3 +1,4 @@
drop function if exists staging2.fn_DBOECD_RUN;
CREATE OR REPLACE FUNCTION staging2.fn_DBOECD_RUN()
RETURNS void AS $$
@@ -6,6 +7,20 @@ CREATE OR REPLACE FUNCTION staging2.fn_DBOECD_RUN()
w_file_syspk int;
status text;
begin
/****************************************************************
******* ForeWarn Licensing and / or usage Terms and Conditions ******
ForeWarn. The NextGen Insights Solution Platform
Copyright 2021 COMPEGENCE. All Rights Reserved
ForeWarn is a product of COMPEGENCE.
To be used only with a valid license from COMPEGENCE
www.compegence.com info@compegence.com
****************************************************************/
for f in select file_syspk from fw_core.fw_jobctl_file_runschedule
where end_status like 'stg1-completed' and file_mnemonic='DBOECD'
loop

View File

@@ -1,3 +1,4 @@
drop function if exists staging2.fn_DBSTD_RUN;
CREATE OR REPLACE FUNCTION staging2.fn_DBSTD_RUN()
RETURNS void AS $$
@@ -6,6 +7,19 @@ CREATE OR REPLACE FUNCTION staging2.fn_DBSTD_RUN()
w_file_syspk int;
status text;
begin
/****************************************************************
******* ForeWarn Licensing and / or usage Terms and Conditions ******
ForeWarn. The NextGen Insights Solution Platform
Copyright 2021 COMPEGENCE. All Rights Reserved
ForeWarn is a product of COMPEGENCE.
To be used only with a valid license from COMPEGENCE
www.compegence.com info@compegence.com
****************************************************************/
for f in select file_syspk from fw_core.fw_jobctl_file_runschedule
where end_status like 'stg1-completed' and file_mnemonic='DBSTD'
loop

View File

@@ -1,3 +1,4 @@
drop function if exists staging2.fn_FTDRY_RUN;
CREATE OR REPLACE FUNCTION staging2.fn_FTDRY_RUN()
RETURNS void AS $$
@@ -6,6 +7,19 @@ CREATE OR REPLACE FUNCTION staging2.fn_FTDRY_RUN()
w_file_syspk int;
status text;
begin
/****************************************************************
******* ForeWarn Licensing and / or usage Terms and Conditions ******
ForeWarn. The NextGen Insights Solution Platform
Copyright 2021 COMPEGENCE. All Rights Reserved
ForeWarn is a product of COMPEGENCE.
To be used only with a valid license from COMPEGENCE
www.compegence.com info@compegence.com
****************************************************************/
for f in select file_syspk from fw_core.fw_jobctl_file_runschedule
where end_status like 'stg1-completed' and file_mnemonic='FTDRY'
loop

View File

@@ -1,3 +1,4 @@
drop function if exists staging2.fn_FTHLG_RUN;
CREATE OR REPLACE FUNCTION staging2.fn_FTHLG_RUN()
RETURNS void AS $$
@@ -6,6 +7,20 @@ CREATE OR REPLACE FUNCTION staging2.fn_FTHLG_RUN()
w_file_syspk int;
status text;
begin
/****************************************************************
******* ForeWarn Licensing and / or usage Terms and Conditions ******
ForeWarn. The NextGen Insights Solution Platform
Copyright 2021 COMPEGENCE. All Rights Reserved
ForeWarn is a product of COMPEGENCE.
To be used only with a valid license from COMPEGENCE
www.compegence.com info@compegence.com
****************************************************************/
for f in select file_syspk from fw_core.fw_jobctl_file_runschedule
where end_status like 'stg1-completed' and file_mnemonic='FTHLG'
loop

View File

@@ -1,3 +1,5 @@
drop function if exists staging2.fn_FTWET_RUN;
CREATE OR REPLACE FUNCTION staging2.fn_FTWET_RUN()
RETURNS void AS $$
@@ -6,6 +8,20 @@ CREATE OR REPLACE FUNCTION staging2.fn_FTWET_RUN()
w_file_syspk int;
status text;
begin
/****************************************************************
******* ForeWarn Licensing and / or usage Terms and Conditions ******
ForeWarn. The NextGen Insights Solution Platform
Copyright 2021 COMPEGENCE. All Rights Reserved
ForeWarn is a product of COMPEGENCE.
To be used only with a valid license from COMPEGENCE
www.compegence.com info@compegence.com
****************************************************************/
for f in select file_syspk from fw_core.fw_jobctl_file_runschedule
where end_status like 'stg1-completed' and file_mnemonic='FTWET'
loop

View File

@@ -1,3 +1,5 @@
drop function if exists staging2.fn_IHTBT30_RUN;
CREATE OR REPLACE FUNCTION staging2.fn_IHTBT30_RUN()
RETURNS void AS $$
@@ -6,6 +8,19 @@ CREATE OR REPLACE FUNCTION staging2.fn_IHTBT30_RUN()
w_file_syspk int;
status text;
begin
/****************************************************************
******* ForeWarn Licensing and / or usage Terms and Conditions ******
ForeWarn. The NextGen Insights Solution Platform
Copyright 2021 COMPEGENCE. All Rights Reserved
ForeWarn is a product of COMPEGENCE.
To be used only with a valid license from COMPEGENCE
www.compegence.com info@compegence.com
****************************************************************/
for f in select file_syspk from fw_core.fw_jobctl_file_runschedule
where end_status like 'stg1-completed' and file_mnemonic = 'IHTBT30' order by file_syspk
loop

View File

@@ -1,3 +1,5 @@
drop function if exists staging2.fn_IHTBT50_RUN;
CREATE OR REPLACE FUNCTION staging2.fn_IHTBT50_RUN()
RETURNS void AS $$
@@ -6,6 +8,18 @@ CREATE OR REPLACE FUNCTION staging2.fn_IHTBT50_RUN()
w_file_syspk int;
status text;
begin
/****************************************************************
******* ForeWarn Licensing and / or usage Terms and Conditions ******
ForeWarn. The NextGen Insights Solution Platform
Copyright 2021 COMPEGENCE. All Rights Reserved
ForeWarn is a product of COMPEGENCE.
To be used only with a valid license from COMPEGENCE
www.compegence.com info@compegence.com
****************************************************************/
for f in select file_syspk from fw_core.fw_jobctl_file_runschedule
where end_status like 'stg1-completed' and file_mnemonic = 'IHTBT50' order by file_syspk
loop

View File

@@ -1,3 +1,5 @@
drop function if exists staging2.fn_IHTBTD_RUN;
CREATE OR REPLACE FUNCTION staging2.fn_IHTBTD_RUN()
RETURNS void AS $$
@@ -6,6 +8,19 @@ CREATE OR REPLACE FUNCTION staging2.fn_IHTBTD_RUN()
w_file_syspk int;
status text;
begin
/****************************************************************
******* ForeWarn Licensing and / or usage Terms and Conditions ******
ForeWarn. The NextGen Insights Solution Platform
Copyright 2021 COMPEGENCE. All Rights Reserved
ForeWarn is a product of COMPEGENCE.
To be used only with a valid license from COMPEGENCE
www.compegence.com info@compegence.com
****************************************************************/
for f in select file_syspk from fw_core.fw_jobctl_file_runschedule
where end_status like 'stg1-completed' and file_mnemonic = 'IHTBTD' order by file_syspk
loop

View File

@@ -1,3 +1,6 @@
drop function if exists staging2.fn_IHTCGM_RUN;
CREATE OR REPLACE FUNCTION staging2.fn_IHTCGM_RUN()
RETURNS void AS $$
@@ -6,6 +9,18 @@ CREATE OR REPLACE FUNCTION staging2.fn_IHTCGM_RUN()
w_file_syspk int;
status text;
begin
/****************************************************************
******* ForeWarn Licensing and / or usage Terms and Conditions ******
ForeWarn. The NextGen Insights Solution Platform
Copyright 2021 COMPEGENCE. All Rights Reserved
ForeWarn is a product of COMPEGENCE.
To be used only with a valid license from COMPEGENCE
www.compegence.com info@compegence.com
****************************************************************/
for f in select file_syspk from fw_core.fw_jobctl_file_runschedule
where end_status like 'stg1-completed' and file_mnemonic = 'IHTCGM' order by file_syspk
loop

View File

@@ -1,3 +1,4 @@
drop function if exists staging2.fn_IHTEMT_RUN;
CREATE OR REPLACE FUNCTION staging2.fn_IHTEMT_RUN()
RETURNS void AS $$
@@ -6,6 +7,19 @@ CREATE OR REPLACE FUNCTION staging2.fn_IHTEMT_RUN()
w_file_syspk int;
status text;
begin
/****************************************************************
******* ForeWarn Licensing and / or usage Terms and Conditions ******
ForeWarn. The NextGen Insights Solution Platform
Copyright 2021 COMPEGENCE. All Rights Reserved
ForeWarn is a product of COMPEGENCE.
To be used only with a valid license from COMPEGENCE
www.compegence.com info@compegence.com
****************************************************************/
for f in select file_syspk from fw_core.fw_jobctl_file_runschedule
where end_status like 'stg1-completed' and file_mnemonic = 'IHTEMT' order by file_syspk
loop

View File

@@ -1,3 +1,5 @@
drop function if exists staging2.fn_IHTHAM_RUN;
CREATE OR REPLACE FUNCTION staging2.fn_IHTHAM_RUN()
RETURNS void AS $$
@@ -6,6 +8,20 @@ CREATE OR REPLACE FUNCTION staging2.fn_IHTHAM_RUN()
w_file_syspk int;
status text;
begin
/****************************************************************
******* ForeWarn Licensing and / or usage Terms and Conditions ******
ForeWarn. The NextGen Insights Solution Platform
Copyright 2021 COMPEGENCE. All Rights Reserved
ForeWarn is a product of COMPEGENCE.
To be used only with a valid license from COMPEGENCE
www.compegence.com info@compegence.com
****************************************************************/
for f in select file_syspk from fw_core.fw_jobctl_file_runschedule
where end_status like 'stg1-completed' and file_mnemonic = 'IHTHAM' order by file_syspk
loop

View File

@@ -1,3 +1,4 @@
drop function if exists staging2.fn_IHTHSL_RUN;
CREATE OR REPLACE FUNCTION staging2.fn_IHTHSL_RUN()
RETURNS void AS $$
@@ -6,6 +7,19 @@ CREATE OR REPLACE FUNCTION staging2.fn_IHTHSL_RUN()
w_file_syspk int;
status text;
begin
/****************************************************************
******* ForeWarn Licensing and / or usage Terms and Conditions ******
ForeWarn. The NextGen Insights Solution Platform
Copyright 2021 COMPEGENCE. All Rights Reserved
ForeWarn is a product of COMPEGENCE.
To be used only with a valid license from COMPEGENCE
www.compegence.com info@compegence.com
****************************************************************/
for f in select file_syspk from fw_core.fw_jobctl_file_runschedule
where end_status like 'stg1-completed' and file_mnemonic = 'IHTHSL' order by file_syspk
loop

View File

@@ -1,3 +1,6 @@
drop function if exists staging2.fn_IHTNST_RUN;
CREATE OR REPLACE FUNCTION staging2.fn_IHTNST_RUN()
RETURNS void AS $$
@@ -6,6 +9,19 @@ CREATE OR REPLACE FUNCTION staging2.fn_IHTNST_RUN()
w_file_syspk int;
status text;
begin
/****************************************************************
******* ForeWarn Licensing and / or usage Terms and Conditions ******
ForeWarn. The NextGen Insights Solution Platform
Copyright 2021 COMPEGENCE. All Rights Reserved
ForeWarn is a product of COMPEGENCE.
To be used only with a valid license from COMPEGENCE
www.compegence.com info@compegence.com
****************************************************************/
for f in select file_syspk from fw_core.fw_jobctl_file_runschedule
where end_status like 'stg1-completed' and file_mnemonic = 'IHTNST' order by file_syspk
loop

View File

@@ -1,3 +1,4 @@
drop function if exists staging2.fn_IHTSLL_RUN;
CREATE OR REPLACE FUNCTION staging2.fn_IHTSLL_RUN()
RETURNS void AS $$
@@ -6,6 +7,19 @@ CREATE OR REPLACE FUNCTION staging2.fn_IHTSLL_RUN()
w_file_syspk int;
status text;
begin
/****************************************************************
******* ForeWarn Licensing and / or usage Terms and Conditions ******
ForeWarn. The NextGen Insights Solution Platform
Copyright 2021 COMPEGENCE. All Rights Reserved
ForeWarn is a product of COMPEGENCE.
To be used only with a valid license from COMPEGENCE
www.compegence.com info@compegence.com
****************************************************************/
for f in select file_syspk from fw_core.fw_jobctl_file_runschedule
where end_status like 'stg1-completed' and file_mnemonic = 'IHTSLL' order by file_syspk
loop

View File

@@ -1,3 +1,5 @@
drop function if exists staging2.fn_PTOBEN_RUN;
CREATE OR REPLACE FUNCTION staging2.fn_PTOBEN_RUN()
RETURNS void AS $$
@@ -6,6 +8,19 @@ CREATE OR REPLACE FUNCTION staging2.fn_PTOBEN_RUN()
w_file_syspk int;
status text;
begin
/****************************************************************
******* ForeWarn Licensing and / or usage Terms and Conditions ******
ForeWarn. The NextGen Insights Solution Platform
Copyright 2021 COMPEGENCE. All Rights Reserved
ForeWarn is a product of COMPEGENCE.
To be used only with a valid license from COMPEGENCE
www.compegence.com info@compegence.com
****************************************************************/
for f in select file_syspk from fw_core.fw_jobctl_file_runschedule
where end_status like 'stg1-completed' and file_mnemonic='PTOBEN'
loop

View File

@@ -1,3 +1,5 @@
drop function if exists staging2.fn_PTOSTD_RUN;
CREATE OR REPLACE FUNCTION staging2.fn_PTOSTD_RUN()
RETURNS void AS $$
@@ -6,6 +8,19 @@ CREATE OR REPLACE FUNCTION staging2.fn_PTOSTD_RUN()
w_file_syspk int;
status text;
begin
/****************************************************************
******* ForeWarn Licensing and / or usage Terms and Conditions ******
ForeWarn. The NextGen Insights Solution Platform
Copyright 2021 COMPEGENCE. All Rights Reserved
ForeWarn is a product of COMPEGENCE.
To be used only with a valid license from COMPEGENCE
www.compegence.com info@compegence.com
****************************************************************/
for f in select file_syspk from fw_core.fw_jobctl_file_runschedule
where end_status like 'stg1-completed' and file_mnemonic='PTOSTD'
loop

223
onetime/wrappers/wrapper_v1.sql Executable file
View File

@@ -0,0 +1,223 @@
CREATE OR REPLACE FUNCTION fw_ods.fn_fw_ods_load(p_client_id int,p_function_id int,p_job_id int,p_step_id int)
RETURNS void
AS $$
declare
f record;
w_job_id int := p_job_id;
w_step_id int := p_step_id;
w_function_id int := p_function_id;
w_client_id int := p_client_id;
w_file_sheet_mnemonic text :='';
error_count int :=0;
begin
/****************************************************************
******* ForeWarn Licensing and / or usage Terms and Conditions ******
ForeWarn. The NextGen Insights Solution Platform
Copyright 2021 COMPEGENCE. All Rights Reserved
ForeWarn is a product of COMPEGENCE.
To be used only with a valid license from COMPEGENCE
www.compegence.com info@compegence.com
****************************************************************/
for f in select distinct file_syspk, file_mnemonic
from fw_core.fw_jobctl_file_runschedule
where latest_runschedule_flag = '1' and
end_status = 'success' and
end_status_note = 'TRX_completed'
order by file_syspk
loop
if f.file_mnemonic in ('FTDRY', 'FTWET', 'FTHLG')
then
perform fw_core.fn_get_function_exception('fw_ods.fn_fw_ods_field_load('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||w_file_sheet_mnemonic||''','||f.file_syspk||')');
perform fw_core.fn_get_function_exception('fw_ods.fn_fw_ods_implement_details_update('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||w_file_sheet_mnemonic||''','||f.file_syspk||')');
perform fw_core.fn_get_function_exception('fw_ods.fn_fw_ods_comments_load('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||w_file_sheet_mnemonic||''','||f.file_syspk||')');
perform fw_core.fn_get_function_exception('fw_ods.fn_fw_ods_observations_load('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||w_file_sheet_mnemonic||''','||f.file_syspk||')');
elsif f.file_mnemonic = 'BUDNI' then
perform fw_core.fn_get_function_exception('fw_ods.fn_fw_ods_budni_load('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||w_file_sheet_mnemonic||''','||f.file_syspk||')');
elsif f.file_mnemonic in ('PTOBEN', 'PTOSTD') then
perform fw_core.fn_get_function_exception('fw_ods.fn_fw_ods_PTO_load('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||w_file_sheet_mnemonic||''','||f.file_syspk||')');
perform fw_core.fn_get_function_exception('fw_ods.fn_fw_ods_pto_observations_load('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||w_file_sheet_mnemonic||''','||f.file_syspk||')');
elsif f.file_mnemonic in ('IHTBT30','IHTBT50','IHTBTD','IHTCGM','IHTHAM','IHTEMT','IHTHLS','IHTNST','IHTSLL') then
perform fw_core.fn_get_function_exception('fw_ods.fn_fw_ods_IHT_load('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||w_file_sheet_mnemonic||''','||f.file_syspk||')');
perform fw_core.fn_get_function_exception('fw_ods.fn_fw_ods_detailed_load('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||w_file_sheet_mnemonic||''','||f.file_syspk||')');
elsif f.file_mnemonic in ('DBOECD', 'DBSTD') then
perform fw_core.fn_get_function_exception('fw_ods.fn_fw_ods_drawbar_performance_load('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||w_file_sheet_mnemonic||''','||f.file_syspk||')');
perform fw_core.fn_get_function_exception('fw_ods.fn_fw_ods_drawbar_load('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||w_file_sheet_mnemonic||''','||f.file_syspk||')');
perform fw_core.fn_get_function_exception('fw_ods.fn_fw_ods_drawbar_observations_load('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||w_file_sheet_mnemonic||''','||f.file_syspk||')');
perform fw_core.fn_get_function_exception('fw_ods.fn_fw_ods_drawbar_comments_load('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||w_file_sheet_mnemonic||''','||f.file_syspk||')');
end if;
select count(status) from fw_core.db_run_status where file_syspk = f.file_syspk and file_mnemonic = f.file_mnemonic and staging_type = 'ods' and status = 'error' into error_count;
if error_count = 0 then
update fw_core.fw_jobctl_file_sheet_runschedule set end_status_note = 'ODS_completed', end_status='success',staging_type = 'ODS',end_time = now()
where file_syspk=f.file_syspk;
update fw_core.fw_jobctl_file_runschedule set end_status_note = 'ODS_completed', end_status='success',staging_type = 'ODS',end_time=now()
where latest_runschedule_flag = '1' and end_status_note ='TRX_completed' and file_syspk = f.file_syspk;
else
update fw_core.fw_jobctl_file_sheet_runschedule set end_status_note = 'ODS_failed', end_status='error',staging_type = 'ODS',end_time = now()
where file_syspk=f.file_syspk;
update fw_core.fw_jobctl_file_runschedule set end_status_note = 'ODS_failed', end_status='error',staging_type = 'ODS',end_time=now()
where latest_runschedule_flag = '1' and end_status_note ='TRX_completed' and file_syspk = f.file_syspk;
end if;
end loop;
--fw_ods
update fw_ods.fw_ods set tractor_model=REGEXP_REPLACE(tractor_model,'\r|\n','','g');
update fw_ods.fw_ods set tractor_make = m.target_value from fw_ods.fw_ods_misnomer m where trim(tractor_make) = m.source_value ;
update fw_ods.fw_ods set tractor_model = m.target_value from fw_ods.fw_ods_misnomer m where trim(tractor_model) = m.source_value ;
update fw_ods.fw_ods set wheel_drive_type = m.target_value from fw_ods.fw_ods_misnomer m where trim(wheel_drive_type) = m.source_value ;
update fw_ods.fw_ods set name_of_implement = m.target_value from fw_ods.fw_ods_misnomer m where trim(name_of_implement) = m.source_value ;
update fw_ods.fw_ods set type_of_implement = m.target_value from fw_ods.fw_ods_misnomer m where trim(type_of_implement) = m.source_value ;
update fw_ods.fw_ods a set "configuration" = m."configuration" from fw_ods.fw_ods_tractor_model_info m where a.tractor_model = m.tractor_model and a."configuration" is null;
update fw_ods.fw_ods a set tractor_engine_hp = m.tractor_engine_hp from fw_ods.fw_ods_tractor_model_info m where a.tractor_model = m.tractor_model and a.tractor_engine_hp is null;
update fw_ods.fw_ods a set wheel_drive_type=m.wheel_drive_type from fw_ods.fw_ods_tractor_model_info m where a.tractor_model = m.tractor_model and a.wheel_drive_type is null;
update fw_ods.fw_ods a set platform = m.platform from fw_ods.fw_ods_tractor_model_info m where a.tractor_model = m.tractor_model and a.platform is null;
update fw_ods.fw_ods a set tractor_make = m.tractor_make from fw_ods.fw_ods_tractor_model_info m where a.tractor_model = m.tractor_model and a.tractor_make is null;
--fw_ods_comments
update fw_ods.fw_ods_comments set tractor_model=REGEXP_REPLACE(tractor_model,'\r|\n','','g');
update fw_ods.fw_ods_comments set tractor_make = m.target_value from fw_ods.fw_ods_misnomer m where trim(tractor_make) = m.source_value ;
update fw_ods.fw_ods_comments set tractor_model = m.target_value from fw_ods.fw_ods_misnomer m where trim(tractor_model) = m.source_value ;
update fw_ods.fw_ods_comments set wheel_drive_type = m.target_value from fw_ods.fw_ods_misnomer m where trim(wheel_drive_type) = m.source_value ;
update fw_ods.fw_ods_comments set name_of_implement = m.target_value from fw_ods.fw_ods_misnomer m where trim(name_of_implement) = m.source_value ;
update fw_ods.fw_ods_comments set type_of_implement = m.target_value from fw_ods.fw_ods_misnomer m where trim(type_of_implement) = m.source_value ;
update fw_ods.fw_ods_comments a set "configuration" = m."configuration" from fw_ods.fw_ods_tractor_model_info m where a.tractor_model = m.tractor_model and a."configuration" is null;
update fw_ods.fw_ods_comments a set tractor_engine_hp = m.tractor_engine_hp from fw_ods.fw_ods_tractor_model_info m where a.tractor_model = m.tractor_model and a.tractor_engine_hp is null;
update fw_ods.fw_ods_comments a set wheel_drive_type=m.wheel_drive_type from fw_ods.fw_ods_tractor_model_info m where a.tractor_model = m.tractor_model and a.wheel_drive_type is null;
update fw_ods.fw_ods_comments a set platform = m.platform from fw_ods.fw_ods_tractor_model_info m where a.tractor_model = m.tractor_model and a.platform is null;
update fw_ods.fw_ods_comments a set tractor_make = m.tractor_make from fw_ods.fw_ods_tractor_model_info m where a.tractor_model = m.tractor_model and a.tractor_make is null;
--fw_ods_drawbar_observations
update fw_ods.fw_ods_drawbar_performance set tractor_model=REGEXP_REPLACE(tractor_model,'\r|\n','','g');
update fw_ods.fw_ods_drawbar_performance set tractor_make = m.target_value from fw_ods.fw_ods_misnomer m where trim(tractor_make) = m.source_value ;
update fw_ods.fw_ods_drawbar_performance set tractor_model = m.target_value from fw_ods.fw_ods_misnomer m where trim(tractor_model) = m.source_value ;
update fw_ods.fw_ods_drawbar_performance set wheel_drive_type = m.target_value from fw_ods.fw_ods_misnomer m where trim(wheel_drive_type) = m.source_value ;
-- update fw_ods.fw_ods_drawbar_performance set name_of_implement = m.target_value from fw_ods.fw_ods_misnomer m where trim(name_of_implement) = m.source_value ;
--update fw_ods.fw_ods_drawbar_performance set type_of_implement = m.target_value from fw_ods.fw_ods_misnomer m where trim(type_of_implement) = m.source_value ;
update fw_ods.fw_ods_drawbar_performance a set "configuration" = m."configuration" from fw_ods.fw_ods_tractor_model_info m where a.tractor_model = m.tractor_model and a."configuration" is null;
update fw_ods.fw_ods_drawbar_performance a set tractor_engine_hp = m.tractor_engine_hp from fw_ods.fw_ods_tractor_model_info m where a.tractor_model = m.tractor_model and a.tractor_engine_hp is null;
update fw_ods.fw_ods_drawbar_performance a set wheel_drive_type=m.wheel_drive_type from fw_ods.fw_ods_tractor_model_info m where a.tractor_model = m.tractor_model and a.wheel_drive_type is null;
update fw_ods.fw_ods_drawbar_performance a set platform = m.platform from fw_ods.fw_ods_tractor_model_info m where a.tractor_model = m.tractor_model and a.platform is null;
update fw_ods.fw_ods_drawbar_performance a set tractor_make = m.tractor_make from fw_ods.fw_ods_tractor_model_info m where a.tractor_model = m.tractor_model and a.tractor_make is null;
--fw_ods_detailed
update fw_ods.fw_ods_detailed set tractor_model=REGEXP_REPLACE(tractor_model,'\r|\n','','g');
update fw_ods.fw_ods_detailed set tractor_make = m.target_value from fw_ods.fw_ods_misnomer m where trim(tractor_make) = m.source_value ;
update fw_ods.fw_ods_detailed set tractor_model = m.target_value from fw_ods.fw_ods_misnomer m where trim(tractor_model) = m.source_value ;
update fw_ods.fw_ods_detailed set wheel_drive_type = m.target_value from fw_ods.fw_ods_misnomer m where trim(wheel_drive_type) = m.source_value ;
-- update fw_ods.fw_ods_detailed set name_of_implement = m.target_value from fw_ods.fw_ods_misnomer m where trim(name_of_implement) = m.source_value ;
--update fw_ods.fw_ods_detailed set type_of_implement = m.target_value from fw_ods.fw_ods_misnomer m where trim(type_of_implement) = m.source_value ;
update fw_ods.fw_ods_detailed a set "configuration" = m."configuration" from fw_ods.fw_ods_tractor_model_info m where a.tractor_model = m.tractor_model and a."configuration" is null;
update fw_ods.fw_ods_detailed a set tractor_engine_hp = m.tractor_engine_hp from fw_ods.fw_ods_tractor_model_info m where a.tractor_model = m.tractor_model and a.tractor_engine_hp is null;
update fw_ods.fw_ods_detailed a set wheel_drive_type=m.wheel_drive_type from fw_ods.fw_ods_tractor_model_info m where a.tractor_model = m.tractor_model and a.wheel_drive_type is null;
update fw_ods.fw_ods_detailed a set platform = m.platform from fw_ods.fw_ods_tractor_model_info m where a.tractor_model = m.tractor_model and a.platform is null;
update fw_ods.fw_ods_detailed a set tractor_make = m.tractor_make from fw_ods.fw_ods_tractor_model_info m where a.tractor_model = m.tractor_model and a.tractor_make is null;
--f_ods_observations
update fw_ods.fw_ods_observations set tractor_model=REGEXP_REPLACE(tractor_model,'\r|\n','','g');
update fw_ods.fw_ods_observations set tractor_make = m.target_value from fw_ods.fw_ods_misnomer m where trim(tractor_make) = m.source_value ;
update fw_ods.fw_ods_observations set tractor_model = m.target_value from fw_ods.fw_ods_misnomer m where trim(tractor_model) = m.source_value ;
update fw_ods.fw_ods_observations set wheel_drive_type = m.target_value from fw_ods.fw_ods_misnomer m where trim(wheel_drive_type) = m.source_value ;
update fw_ods.fw_ods_observations set name_of_implement = m.target_value from fw_ods.fw_ods_misnomer m where trim(name_of_implement) = m.source_value ;
update fw_ods.fw_ods_observations set type_of_implement = m.target_value from fw_ods.fw_ods_misnomer m where trim(type_of_implement) = m.source_value ;
update fw_ods.fw_ods_observations a set "configuration" = m."configuration" from fw_ods.fw_ods_tractor_model_info m where a.tractor_model = m.tractor_model and a."configuration" is null;
update fw_ods.fw_ods_observations a set tractor_engine_hp = m.tractor_engine_hp from fw_ods.fw_ods_tractor_model_info m where a.tractor_model = m.tractor_model and a.tractor_engine_hp is null;
update fw_ods.fw_ods_observations a set wheel_drive_type=m.wheel_drive_type from fw_ods.fw_ods_tractor_model_info m where a.tractor_model = m.tractor_model and a.wheel_drive_type is null;
update fw_ods.fw_ods_observations a set platform = m.platform from fw_ods.fw_ods_tractor_model_info m where a.tractor_model = m.tractor_model and a.platform is null;
update fw_ods.fw_ods_observations a set tractor_make = m.tractor_make from fw_ods.fw_ods_tractor_model_info m where a.tractor_model = m.tractor_model and a.tractor_make is null;
-- Additional Updates:
-- Gear Used:
update fw_ods.fw_ods set gear_used = m.target_value from fw_ods.fw_ods_misnomer m where trim(gear_used) = m.source_value;
update fw_ods.fw_ods_comments set gear_used = m.target_value from fw_ods.fw_ods_misnomer m where trim(gear_used) = m.source_value;
update fw_ods.fw_ods_drawbar_performance set gear_used = m.target_value from fw_ods.fw_ods_misnomer m where trim(gear_used) = m.source_value;
update fw_ods.fw_ods_observations set gear_used = m.target_value from fw_ods.fw_ods_misnomer m where trim(gear_used) = m.source_value;
-- Sensor body Location:
update fw_ods.fw_ods set sensor_body_location = m.target_value from fw_ods.fw_ods_misnomer m where trim(sensor_body_location) = m.source_value;
update fw_core.fw_jobctl_runschedule_jobstep set end_status_note = 'ODS_completed', end_status='success', end_time=now() where job_id = p_job_id and step_id = p_step_id and latest_runschedule_flag = '1';
end
$$
LANGUAGE plpgsql;