rename folder
This commit is contained in:
199
Deepthi_SQL/execute functions/budni_dbp_execute.sql
Normal file
199
Deepthi_SQL/execute functions/budni_dbp_execute.sql
Normal file
@@ -0,0 +1,199 @@
|
||||
drop function if exists mmt_staging2.fn_BUDNI_DBP_Block ;
|
||||
CREATE OR REPLACE FUNCTION mmt_staging2.fn_BUDNI_DBP_Block(p_client_id int,p_function_id int, p_file_format text,
|
||||
p_sheet_mnemonic text, p_file_syspk int)
|
||||
RETURNS void AS $$
|
||||
declare __make text;
|
||||
declare __model text;
|
||||
begin
|
||||
|
||||
SET search_path TO mmt_staging2;
|
||||
|
||||
delete from mmt_staging2.BUDNI_DBP_Spec_H1_Block;
|
||||
delete from mmt_staging2.BUDNI_DBP_Drawbar_Perf_Block;
|
||||
delete from mmt_staging2.stg_specific_table_budni_dbp;
|
||||
delete from mmt_staging2.stg_process_table_budni_dbp;
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_number_start=null,
|
||||
row_previous_number=null,
|
||||
row_read_end=null,
|
||||
run_time=null
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
|
||||
execute 'insert into mmt_staging2.stg_specific_table_budni_dbp
|
||||
select * from mmt_staging1.mmt_staging_generic_table a
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
and a.file_syspk='||p_file_syspk||'';
|
||||
|
||||
|
||||
execute 'update mmt_staging2.stg_specific_table_budni_dbp set column2 = TRIM (TRAILING FROM column2 )';
|
||||
execute 'update mmt_staging2.stg_specific_table_budni_dbp set column2 = TRIM (LEADING FROM column2 )';
|
||||
|
||||
|
||||
execute 'update mmt_ods.mmt_config set F1_modified = TRIM (TRAILING FROM F1_modified)';
|
||||
execute 'update mmt_ods.mmt_config set F1_modified = TRIM (LEADING FROM F1_modified)' ;
|
||||
execute 'update mmt_ods.mmt_config set F1_source=F1_modified' ;
|
||||
execute 'update mmt_ods.mmt_config set F1_source = TRIM (TRAILING FROM F1_source)';
|
||||
execute 'update mmt_ods.mmt_config set F1_source = TRIM (LEADING FROM F1_source)' ;
|
||||
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_number_start=(select min(b.row_number)
|
||||
from mmt_staging2.stg_specific_table_budni_dbp b
|
||||
where trim(upper(F1_source))= trim(upper(column3))
|
||||
and b.is_rownumber_fetched is null)
|
||||
where a.row_number_start is null
|
||||
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_staging2.stg_specific_table_budni_dbp a
|
||||
set is_rownumber_fetched=1
|
||||
from mmt_ods.mmt_config b
|
||||
where trim(upper(F1_source))= trim(upper(column3))
|
||||
and b.row_number_start=a.row_number
|
||||
and is_rownumber_fetched is null and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_ods.mmt_config a set row_previous_number=row_number_start-1
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_read_end= (select b.row_number_start
|
||||
from mmt_ods.mmt_config b
|
||||
where b.syspk=a.syspk+1 )
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_read_end = null
|
||||
where f1_modified =''Tractor Drawbar Performance Report''
|
||||
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set run_time=current_timestamp
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_budni_dbp
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_budni_dbp a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Tractor Specifiactions''
|
||||
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_budni_dbp
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_budni_dbp a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Tractor Drawbar Performance Report.''
|
||||
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
delete from mmt_staging2.stg_process_table_budni_dbp where row_number between 37 and 42;
|
||||
|
||||
select column3 into __make from mmt_staging2.stg_process_table_budni_dbp a
|
||||
where rank_tag='BUDNI_DBP_Spec_H1' and rank=2;
|
||||
|
||||
select column4 into __model from mmt_staging2.stg_process_table_budni_dbp a
|
||||
where rank_tag='BUDNI_DBP_Spec_H1' and rank=2;
|
||||
|
||||
|
||||
|
||||
|
||||
insert into mmt_staging2.BUDNI_DBP_Spec_H1_Block
|
||||
(
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,column10,column11,column12,column13,
|
||||
column14,column15,rank
|
||||
)
|
||||
select
|
||||
column2,column3,column4,column5,column6,column7,column8,column9,column10,
|
||||
column11,column12,column13,column14,column15,rank
|
||||
from mmt_staging2.stg_process_table_budni_dbp
|
||||
where rank_tag='BUDNI_DBP_Spec_H1';
|
||||
|
||||
|
||||
update mmt_staging2.BUDNI_DBP_Spec_H1_Block
|
||||
set ods_record=0 where rank in
|
||||
(select distinct first_value(b.rank)
|
||||
over (partition by b.column2 order by b.syspk) from mmt_staging2.BUDNI_DBP_Spec_H1_Block b);
|
||||
|
||||
|
||||
execute 'update mmt_staging2.BUDNI_DBP_Spec_H1_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
execute 'insert into mmt_staging2.BUDNI_DBP_Drawbar_Perf_Block
|
||||
(
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,column10,column11,column12,column13,
|
||||
column14,column15,column16,column17,column18,column19,rank
|
||||
)
|
||||
select
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,column10,column11,column12,column13,column14,
|
||||
column15,column16,column17,column18,column19,rank
|
||||
from mmt_staging2.stg_process_table_budni_dbp a
|
||||
where rank_tag=''BUDNI_DBP_Drawbar_Perf''';
|
||||
|
||||
|
||||
update mmt_staging2.BUDNI_DBP_Drawbar_Perf_Block set make=__make,model=__model;
|
||||
execute 'update mmt_staging2.BUDNI_DBP_Drawbar_Perf_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
|
||||
update mmt_staging2.BUDNI_DBP_Drawbar_Perf_Block
|
||||
set column2= column3 where column3 like 'i%';
|
||||
|
||||
update mmt_staging2.BUDNI_DBP_Drawbar_Perf_Block
|
||||
set column3=null
|
||||
where column3 like 'i%';
|
||||
|
||||
update mmt_staging2.BUDNI_DBP_Drawbar_Perf_Block a
|
||||
set column2= b.first_value from (SELECT
|
||||
rank, column2, value_partition, first_value(column2) over (partition by value_partition order by rank)
|
||||
FROM (
|
||||
SELECT
|
||||
rank,
|
||||
column2,
|
||||
sum(case when column2 is null then 0 else 1 end) over (order by rank) as value_partition
|
||||
FROM mmt_staging2.BUDNI_DBP_Drawbar_Perf_Block
|
||||
ORDER BY rank ASC
|
||||
) as q) b where a.rank = b.rank;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
update mmt_staging2.BUDNI_DBP_Drawbar_Perf_Block
|
||||
set ods_record=0 where column4 is null or
|
||||
rank in
|
||||
(select distinct first_value(b.rank)
|
||||
over (partition by b.column2 order by b.syspk) from mmt_staging2.BUDNI_DBP_Drawbar_Perf_Block b);
|
||||
|
||||
|
||||
|
||||
end
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
|
||||
select mmt_staging2.fn_BUDNI_DBP_Block(20,1,'BUDNI','BUDNI_DBP',182);
|
||||
|
||||
|
||||
283
Deepthi_SQL/execute functions/budni_pto_execute.sql
Normal file
283
Deepthi_SQL/execute functions/budni_pto_execute.sql
Normal file
@@ -0,0 +1,283 @@
|
||||
drop function if exists mmt_staging2.fn_BUDNI_PTO_block;
|
||||
CREATE OR REPLACE FUNCTION mmt_staging2.fn_BUDNI_PTO_block(p_client_id int,p_function_id int, p_file_format text,
|
||||
p_sheet_mnemonic text, p_file_syspk int)
|
||||
RETURNS text AS $$
|
||||
declare __make text;
|
||||
declare __model text;
|
||||
begin
|
||||
|
||||
SET search_path TO mmt_staging2;
|
||||
|
||||
delete from mmt_staging2.stg_specific_table_BUDNI_PTO;
|
||||
delete from mmt_staging2.stg_process_table_BUDNI_PTO;
|
||||
delete from mmt_staging2.BUDNI_PTO_Spec_H1_Block;
|
||||
delete from mmt_staging2.BUDNI_PTO_Perf_Report_block;
|
||||
delete from mmt_staging2.BUDNI_PTO_MMTKeyword1_Block;
|
||||
delete from mmt_staging2.BUDNI_PTO_MMTKeyword2_Block;
|
||||
delete from mmt_staging2.BUDNI_PTO_Summary_Block;
|
||||
|
||||
/* rerun */
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_number_start=null,
|
||||
row_previous_number=null,
|
||||
row_read_end=null,
|
||||
run_time=null
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
execute 'insert into mmt_staging2.stg_specific_table_budni_pto
|
||||
select * from mmt_staging1.mmt_staging_generic_table a
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
and a.file_syspk='||p_file_syspk||'';
|
||||
|
||||
|
||||
update mmt_staging2.stg_specific_table_budni_pto set column3 = TRIM (TRAILING FROM column3 );
|
||||
update mmt_staging2.stg_specific_table_budni_pto set column3 = TRIM (LEADING FROM column3 );
|
||||
|
||||
update mmt_ods.mmt_config set F1_modified = TRIM (TRAILING FROM F1_modified) ;
|
||||
update mmt_ods.mmt_config set F1_modified = TRIM (LEADING FROM F1_modified) ;
|
||||
update mmt_ods.mmt_config set F1_source=F1_modified ;
|
||||
update mmt_ods.mmt_config set F1_source = TRIM (TRAILING FROM F1_source);
|
||||
update mmt_ods.mmt_config set F1_source = TRIM (LEADING FROM F1_source);
|
||||
|
||||
/* keyword match */
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_number_start=(select min(b.row_number)
|
||||
from mmt_staging2.stg_specific_table_budni_pto b
|
||||
where trim(upper(F1_modified))=trim(upper(column3))
|
||||
and b.is_rownumber_fetched is null)
|
||||
where a.row_number_start is null
|
||||
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
/* reverese update */
|
||||
execute 'update mmt_staging2.stg_specific_table_budni_pto a
|
||||
set is_rownumber_fetched=1
|
||||
from mmt_ods.mmt_config b
|
||||
where trim(upper(F1_modified))=trim(upper(column3))
|
||||
and b.row_number_start=a.row_number
|
||||
and is_rownumber_fetched is null
|
||||
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_ods.mmt_config a set row_previous_number=row_number_start-1
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_read_end= (select b.row_number_start
|
||||
from mmt_ods.mmt_config b
|
||||
where b.syspk=a.syspk+1 and file_format='''||p_file_format||''' and sheet_mnemonic='''||p_sheet_mnemonic||''' )
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
/* last field */
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_read_end = null ,run_time=current_timestamp
|
||||
where f1_modified =''PTO Performance Test Observations Summary''
|
||||
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
/* tagging ranks*/
|
||||
execute 'insert into mmt_staging2.stg_process_table_budni_pto
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_budni_pto a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Tractor Specifiactions''
|
||||
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_budni_pto
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_budni_pto a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''PTO Performance Report''
|
||||
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_budni_pto
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag from mmt_staging2.stg_specific_table_budni_pto a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''MMTKeyword1''
|
||||
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_budni_pto
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag from mmt_staging2.stg_specific_table_budni_pto a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''MMTKeyword2''
|
||||
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_budni_pto
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_budni_pto a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''PTO Performance Test Observations Summary''
|
||||
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
delete from mmt_staging2.stg_process_table_budni_pto where row_number between 42 and 47;
|
||||
|
||||
select column3 into __make from mmt_staging2.stg_process_table_budni_pto a
|
||||
where rank_tag='BUDNI_PTO_Spec_H1' and rank=3 ;
|
||||
|
||||
select column4 into __model from mmt_staging2.stg_process_table_budni_pto a
|
||||
where rank_tag='BUDNI_PTO_Spec_H1' and rank=3;
|
||||
|
||||
/* blocks */
|
||||
insert into mmt_staging2.BUDNI_PTO_Spec_H1_block
|
||||
(make,model,tractor_HP,rated_rpm,configuration,transmission_type,wheel_drive_type,FIP_type,rank)
|
||||
select column3,column4,column5,column6,column7,column8,column9,column10,rank
|
||||
from mmt_staging2.stg_process_table_budni_pto where rank_tag='BUDNI_PTO_Spec_H1'
|
||||
and rank=3;
|
||||
|
||||
|
||||
execute 'update mmt_staging2.BUDNI_PTO_Spec_H1_block set file_syspk='||p_file_syspk||'';
|
||||
|
||||
update mmt_staging2.BUDNI_PTO_Spec_H1_block a
|
||||
set date= date '1899-12-30' + column12::int * interval '1' day
|
||||
from mmt_staging2.stg_process_table_budni_pto b
|
||||
where b.rank_tag='BUDNI_PTO_Spec_H1'
|
||||
and b.rank=1
|
||||
and a.file_syspk=b.file_syspk ;
|
||||
|
||||
|
||||
|
||||
update mmt_staging2.BUDNI_PTO_Spec_H1_block a
|
||||
set steering_type=column3,Engine_to_PTO_ratio= column4
|
||||
from mmt_staging2.stg_process_table_budni_pto b
|
||||
where b.rank_tag='BUDNI_PTO_Spec_H1'
|
||||
and b.rank=5
|
||||
and a.file_syspk=b.file_syspk;
|
||||
|
||||
update mmt_staging2.BUDNI_PTO_Spec_H1_block set make=__make, model=__model;
|
||||
execute 'update mmt_staging2.BUDNI_PTO_Spec_H1_block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||''',
|
||||
file_syspk='||p_file_syspk||'';
|
||||
|
||||
|
||||
/*block */
|
||||
insert into mmt_staging2.BUDNI_PTO_Perf_Report_block
|
||||
( column2,column3,column4,column5,column6,column7,column8,column9,column10,rank)
|
||||
select column2,column3,column4,column5,column6,column7,column8,column9,column10,rank
|
||||
from mmt_staging2.stg_process_table_budni_pto
|
||||
where rank_tag='BUDNI_PTO_Perf_Report';
|
||||
|
||||
|
||||
update mmt_staging2.BUDNI_PTO_Perf_Report_block
|
||||
set column2=column3 where column2 is null;
|
||||
|
||||
update mmt_staging2.BUDNI_PTO_Perf_Report_block
|
||||
set column2=null
|
||||
where column2 like 'i%';
|
||||
|
||||
update mmt_staging2.BUDNI_PTO_Perf_Report_block
|
||||
set column2=null
|
||||
where column2 like 'v%';
|
||||
|
||||
update mmt_staging2.BUDNI_PTO_Perf_Report_block a
|
||||
set column2= b.first_value from (SELECT
|
||||
rank, column2, value_partition, first_value(column2) over (partition by value_partition order by rank)
|
||||
FROM (
|
||||
SELECT
|
||||
rank,
|
||||
column2,
|
||||
sum(case when column2 is null then 0 else 1 end) over (order by rank) as value_partition
|
||||
FROM mmt_staging2.BUDNI_PTO_Perf_Report_block
|
||||
ORDER BY rank ASC
|
||||
) as q) b where a.rank = b.rank ;
|
||||
|
||||
update mmt_staging2.BUDNI_PTO_Perf_Report_block
|
||||
set column3 =null
|
||||
where column2=column3;
|
||||
|
||||
update mmt_staging2.BUDNI_PTO_Perf_Report_block
|
||||
set ods_record=0 where rank in (1,2,3);
|
||||
|
||||
|
||||
update mmt_staging2.BUDNI_PTO_Perf_Report_block set ods_record=0 where column3 is null
|
||||
and column2 in(
|
||||
select column2 from mmt_staging2.BUDNI_PTO_Perf_Report_block group by column2 having count(*)>1
|
||||
);
|
||||
|
||||
|
||||
|
||||
update mmt_staging2.BUDNI_PTO_Perf_Report_block set make=__make,model=__model;
|
||||
execute 'update mmt_staging2.BUDNI_PTO_Perf_Report_block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||''',
|
||||
file_syspk='||p_file_syspk||'';
|
||||
|
||||
|
||||
/* block */
|
||||
insert into mmt_staging2.BUDNI_PTO_MMTKeyword1_block
|
||||
( column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,rank)
|
||||
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,rank
|
||||
from mmt_staging2.stg_process_table_budni_pto
|
||||
where rank_tag='BUDNI_PTO_MMTKeyword1';
|
||||
|
||||
|
||||
update mmt_staging2.BUDNI_PTO_MMTKeyword1_block set ods_record=0 where rank in (1,2);
|
||||
|
||||
update mmt_staging2.BUDNI_PTO_MMTKeyword1_block set make=__make,model=__model;
|
||||
execute 'update mmt_staging2.BUDNI_PTO_MMTKeyword1_block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||''',
|
||||
file_syspk='||p_file_syspk||'';
|
||||
|
||||
/* block */
|
||||
|
||||
insert into mmt_staging2.BUDNI_PTO_MMTKeyword2_block
|
||||
( column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,rank)
|
||||
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,rank
|
||||
from mmt_staging2.stg_process_table_budni_pto
|
||||
where rank_tag='BUDNI_PTO_MMTKeyword2';
|
||||
|
||||
|
||||
update mmt_staging2.BUDNI_PTO_MMTKeyword2_block set ods_record=0 where rank in (1,2);
|
||||
|
||||
|
||||
update mmt_staging2.BUDNI_PTO_MMTKeyword2_block set make=__make,model=__model;
|
||||
execute 'update mmt_staging2.BUDNI_PTO_MMTKeyword2_block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||''',
|
||||
file_syspk='||p_file_syspk||'';
|
||||
|
||||
|
||||
/* block */
|
||||
|
||||
insert into mmt_staging2.BUDNI_PTO_Summary_Block
|
||||
( column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,rank)
|
||||
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,rank
|
||||
from mmt_staging2.stg_process_table_budni_pto
|
||||
where rank_tag='BUDNI_PTO_Summary';
|
||||
|
||||
|
||||
update mmt_staging2.BUDNI_PTO_Summary_block
|
||||
set ods_record=0 where rank in (1,2);
|
||||
|
||||
update mmt_staging2.BUDNI_PTO_Summary_block set make=__make, model=__model;
|
||||
execute 'update mmt_staging2.BUDNI_PTO_Summary_block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||''',
|
||||
file_syspk='||p_file_syspk||'';
|
||||
|
||||
return __model;
|
||||
|
||||
end
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
select mmt_staging2.fn_BUDNI_PTO_block(20,1,'BUDNI','BUDNI_PTO',182);
|
||||
|
||||
397
Deepthi_SQL/execute functions/dry_sum_execute.sql
Normal file
397
Deepthi_SQL/execute functions/dry_sum_execute.sql
Normal file
@@ -0,0 +1,397 @@
|
||||
drop function if exists mmt_staging2.fn_FTDRY_SUM_Block ;
|
||||
CREATE OR REPLACE FUNCTION mmt_staging2.fn_FTDRY_SUM_Block(p_client_id int,p_function_id int, p_file_format text,
|
||||
p_sheet_mnemonic text, p_file_syspk int)
|
||||
RETURNS void AS $$
|
||||
begin
|
||||
|
||||
SET search_path TO mmt_staging2;
|
||||
|
||||
delete from mmt_staging2.ftdry_sum_trac_h1_block;
|
||||
delete from mmt_staging2.ftdry_sum_implement_block;
|
||||
delete from mmt_staging2.ftdry_sum_test_condition_1_block;
|
||||
delete from mmt_staging2.ftdry_sum_test_condition_2_block;
|
||||
delete from mmt_staging2.ftdry_sum_comments_by_block;
|
||||
delete from mmt_staging2.stg_specific_table_ftdry_sum;
|
||||
delete from mmt_staging2.stg_process_table_ftdry_sum;
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_number_start=null,
|
||||
row_previous_number=null,
|
||||
row_read_end=null,
|
||||
run_time=null
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
|
||||
execute 'insert into mmt_staging2.stg_specific_table_ftdry_sum
|
||||
select * from mmt_staging1.mmt_staging_generic_table a
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
and a.file_syspk='||p_file_syspk||'';
|
||||
|
||||
|
||||
update mmt_staging2.stg_specific_table_ftdry_sum set column2 = TRIM (TRAILING FROM column2 );
|
||||
update mmt_staging2.stg_specific_table_ftdry_sum set column2 = TRIM (LEADING FROM column2 );
|
||||
|
||||
|
||||
update mmt_ods.mmt_config set F1_modified = TRIM (TRAILING FROM F1_modified);
|
||||
update mmt_ods.mmt_config set F1_modified = TRIM (LEADING FROM F1_modified) ;
|
||||
update mmt_ods.mmt_config set F1_source=F1_modified ;
|
||||
update mmt_ods.mmt_config set F1_source = TRIM (TRAILING FROM F1_source);
|
||||
update mmt_ods.mmt_config set F1_source = TRIM (LEADING FROM F1_source) ;
|
||||
|
||||
execute 'update mmt_ods.mmt_config a set f1_source = replace(f1_source,''_1'','''')
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_number_start=(select min(b.row_number)
|
||||
from mmt_staging2.stg_specific_table_ftdry_sum b
|
||||
where F1_source=column2
|
||||
and b.is_rownumber_fetched is null)
|
||||
where a.row_number_start is null and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_staging2.stg_specific_table_ftdry_sum a
|
||||
set is_rownumber_fetched=1
|
||||
from mmt_ods.mmt_config b
|
||||
where F1_source=column2
|
||||
and b.row_number_start=a.row_number
|
||||
and is_rownumber_fetched is null and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_ods.mmt_config a set f1_source = replace(f1_source,''_2'','''')
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_number_start=(select min(b.row_number)
|
||||
from mmt_staging2.stg_specific_table_ftdry_sum b
|
||||
where F1_source=column2
|
||||
and b.is_rownumber_fetched is null)
|
||||
where a.row_number_start is null and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_staging2.stg_specific_table_ftdry_sum a
|
||||
set is_rownumber_fetched=1
|
||||
from mmt_ods.mmt_config b
|
||||
where F1_source=column2
|
||||
and b.row_number_start=a.row_number
|
||||
and is_rownumber_fetched is null and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_ods.mmt_config a set row_previous_number=row_number_start-1
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_read_end= (select b.row_number_start
|
||||
from mmt_ods.mmt_config b
|
||||
where b.syspk=a.syspk+1 )
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_read_end = null where f1_modified =''Test Manager Comments_2'' and
|
||||
a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set run_time=current_timestamp where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_ftdry_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_ftdry_sum a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Tractor Model''
|
||||
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_ftdry_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_ftdry_sum a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Make of Implement''
|
||||
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_ftdry_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_ftdry_sum a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Condition_1:''
|
||||
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_ftdry_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_ftdry_sum a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Engineer Comments_1''
|
||||
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_ftdry_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_ftdry_sum a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Manager Comments_1''
|
||||
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_ftdry_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_ftdry_sum a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Condition_2:''
|
||||
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_ftdry_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_ftdry_sum a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Engineer Comments_2''
|
||||
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_ftdry_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_ftdry_sum a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Manager Comments_2''
|
||||
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
insert into mmt_staging2.FTDRY_SUM_Trac_H1_Block
|
||||
(
|
||||
Tractor_Model,
|
||||
Tractor_Make,
|
||||
Tractor_Engine_HP,
|
||||
Rated_RPM,
|
||||
Transmission_Type,
|
||||
Wheel_Drive_Type,
|
||||
FIP_Type,
|
||||
Steering_Type,
|
||||
Tractor_Weight_kg_Front,
|
||||
Tractor_Weight_kg_Rear,
|
||||
Tractor_Weight_kg_Total
|
||||
)
|
||||
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12
|
||||
from mmt_staging2.stg_process_table_ftdry_sum
|
||||
where rank_tag='FTDRY_SUM_Trac_H1' and rank <> 1;
|
||||
|
||||
/*delete from mmt_staging2.FTWET_TRS_SPEC_Block where dummy_f is null ;*/
|
||||
execute 'update mmt_staging2.FTDRY_SUM_Trac_H1_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
insert into mmt_staging2.FTDRY_SUM_Implement_Block
|
||||
(
|
||||
Make_of_Implement,
|
||||
Implement_Type,
|
||||
Implement_Size,
|
||||
Hitch_Category,
|
||||
Implement_Weight,
|
||||
Soil_Type,
|
||||
Moisture_Content ,
|
||||
Bulk_Density_g_cc ,
|
||||
Soil_Cone_index,
|
||||
Field_Condition ,
|
||||
Season
|
||||
)
|
||||
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12
|
||||
from mmt_staging2.stg_process_table_ftdry_sum
|
||||
where rank_tag='FTDRY_SUM_Implement' and rank not in(1,3);
|
||||
|
||||
/*delete from mmt_staging2.FTDRY_SUM_Implement_Block where dummy_f is null */
|
||||
execute 'update mmt_staging2.FTDRY_SUM_Implement_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
insert into mmt_staging2.FTDRY_SUM_Test_Condition_1_Block
|
||||
(
|
||||
dummy_f,
|
||||
Test_Condition,
|
||||
Test_Date,
|
||||
Tractor_Model,
|
||||
Engine_RPM_set,
|
||||
PTO_RPM_set,
|
||||
Gear_Used,
|
||||
Nominal_Speed_KMPH,
|
||||
Engine_RPM_Drop_on_straight,
|
||||
Engine_RPM_Drop_on_turn,
|
||||
Depth_of_cut_cm,
|
||||
No_load_speed_kmph,
|
||||
On_load_speed_kmph,
|
||||
wheel_slippage_,
|
||||
Fuel_consumption_lit_hr,
|
||||
Area_covered_acr_hr,
|
||||
Fuel_consumption_lit_Acr,
|
||||
M_M_Performance_in_compared_to_respective_competitor_tractors,
|
||||
Fuel_consumption_lit_hr_2,
|
||||
Area_covered_acr_hr_2,
|
||||
Fuel_consumption_lit_Acr_2,
|
||||
Trail_Observations,
|
||||
Engine_Smoke_on_Load,
|
||||
Engine_acceleration_smoke,
|
||||
Draft_Response,
|
||||
Tractor_Steer_ability,
|
||||
Tractor_braking_performance,
|
||||
Front_Visibility,
|
||||
Implement_Accessibility,
|
||||
Front_Wheel_dragging_at_turning,
|
||||
Front_end_lifting_during_operation,
|
||||
RPM_Recovery_Time,
|
||||
Engine_Vibration,
|
||||
Engine_Sound,
|
||||
Implement_Lifting_Lowering_response,
|
||||
Pulverization_Quality,
|
||||
Pulverization_Index
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3,column4,column5,column6,column7,column8,column9,column10,column11,column12}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text,
|
||||
column4::text,column5::text,column6::text,column7::text,column8::text,
|
||||
column9::text,column10::text,column11::text,column12::text]) AS val
|
||||
FROM mmt_staging2.stg_process_table_ftdry_sum where rank_tag=''FTDRY_SUM_Test_Condition_1''
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text,
|
||||
a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text
|
||||
,a_21 text,a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text,
|
||||
a_31 text,a_32 text,a_33 text,a_34 text,a_35 text,a_36 text);
|
||||
|
||||
delete from mmt_staging2.FTDRY_SUM_Test_Condition_1_Block where dummy_f is null ;
|
||||
execute 'update mmt_staging2.FTDRY_SUM_Test_Condition_1_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
insert into mmt_staging2.FTDRY_SUM_Test_Condition_2_Block
|
||||
(
|
||||
dummy_f,
|
||||
Test_Condition,
|
||||
Test_Date,
|
||||
Tractor_Model,
|
||||
Engine_RPM_set,
|
||||
PTO_RPM_set,
|
||||
Gear_Used,
|
||||
Nominal_Speed_KMPH,
|
||||
Engine_RPM_Drop_on_straight,
|
||||
Engine_RPM_Drop_on_turn,
|
||||
Depth_of_cut_cm,
|
||||
No_load_speed_kmph,
|
||||
On_load_speed_kmph,
|
||||
wheel_slippage_,
|
||||
Fuel_consumption_lit_hr,
|
||||
Area_covered_acr_hr,
|
||||
Fuel_consumption_lit_Acr,
|
||||
M_M_Performance_in_compared_to_respective_competitor_tractors,
|
||||
Fuel_consumption_lit_hr_2,
|
||||
Area_covered_acr_hr_2,
|
||||
Fuel_consumption_lit_Acr_2,
|
||||
Trail_Observations,
|
||||
Engine_Smoke_on_Load,
|
||||
Engine_acceleration_smoke,
|
||||
Draft_Response,
|
||||
Tractor_Steer_ability,
|
||||
Tractor_braking_performance,
|
||||
Front_Visibility,
|
||||
Implement_Accessibility,
|
||||
Front_Wheel_dragging_at_turning,
|
||||
Front_end_lifting_during_operation,
|
||||
RPM_Recovery_Time,
|
||||
Engine_Vibration,
|
||||
Engine_Sound,
|
||||
Implement_Lifting_Lowering_response,
|
||||
Pulverization_Quality,
|
||||
Pulverization_Index
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3,column4,column5,column6,column7,column8,column9,column10,column11,column12}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text,column8::text,column9::text,column10::text,column11::text,column12::text]) AS val
|
||||
FROM mmt_staging2.stg_process_table_ftdry_sum where rank_tag=''FTDRY_SUM_Test_Condition_2''
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,
|
||||
a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text,a_21 text,
|
||||
a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text,a_31 text,
|
||||
a_32 text,a_33 text,a_34 text,a_35 text,a_36 text);
|
||||
|
||||
delete from mmt_staging2.FTDRY_SUM_Test_Condition_2_Block where dummy_f is null ;
|
||||
execute 'update mmt_staging2.FTDRY_SUM_Test_Condition_2_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
insert into mmt_staging2.FTDRY_SUM_Comments_By_Block (dummy_f) values ('dummy');
|
||||
|
||||
execute 'update mmt_staging2.FTDRY_SUM_Comments_By_Block set Test_Engineer_Comments_1=
|
||||
(select column3 from mmt_staging2.stg_process_table_ftdry_sum a
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
and a.rank_tag=''FTDRY_SUM_Engineer_Comments_1''
|
||||
and a.rank=1 ) where dummy_f=''dummy''';
|
||||
|
||||
execute 'update mmt_staging2.FTDRY_SUM_Comments_By_Block set test_engineer_comments_2=
|
||||
(select column3 from mmt_staging2.stg_process_table_ftdry_sum a
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
and a.rank_tag=''FTDRY_SUM_Engineer_Comments_2''
|
||||
and a.rank=1 ) where dummy_f=''dummy''';
|
||||
|
||||
execute 'update mmt_staging2.FTDRY_SUM_Comments_By_Block set test_manager_comments_1=
|
||||
(select column3 from mmt_staging2.stg_process_table_ftdry_sum a
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
and a.rank_tag=''FTDRY_SUM_Manager_Comments_1''
|
||||
and a.rank=1 ) where dummy_f=''dummy''';
|
||||
|
||||
execute 'update mmt_staging2.FTDRY_SUM_Comments_By_Block set test_manager_comments_2=
|
||||
(select column3 from mmt_staging2.stg_process_table_ftdry_sum a
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
and a.rank_tag=''FTDRY_SUM_Manager_Comments_2''
|
||||
and a.rank=1 ) where dummy_f=''dummy''';
|
||||
|
||||
|
||||
delete from mmt_staging2.FTDRY_SUM_Comments_By_Block where dummy_f is null ;
|
||||
execute 'update mmt_staging2.FTDRY_SUM_Comments_By_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
end
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
select mmt_staging2.fn_FTDRY_SUM_Block (20,1,'FTDRY','FTDRY_SUM',179);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
345
Deepthi_SQL/execute functions/dry_trs_execute.sql
Normal file
345
Deepthi_SQL/execute functions/dry_trs_execute.sql
Normal file
@@ -0,0 +1,345 @@
|
||||
/*FTDRY_starts*/
|
||||
drop function if exists mmt_staging2.fn_FTDRY_TRS_Block ;
|
||||
CREATE OR REPLACE FUNCTION mmt_staging2.fn_FTDRY_TRS_Block(p_client_id int,p_function_id int, p_file_format text,
|
||||
p_sheet_mnemonic text, p_file_syspk int)
|
||||
RETURNS void AS $$
|
||||
begin
|
||||
|
||||
SET search_path TO mmt_staging2;
|
||||
|
||||
delete from mmt_staging2.FTDRY_TRS_H1_INT;
|
||||
delete from mmt_staging2.ftdry_trs_h1_block ;
|
||||
delete from mmt_staging2.ftdry_trs_implement_block ;
|
||||
delete from mmt_staging2.ftdry_trs_spec_block;
|
||||
delete from mmt_staging2.ftdry_trs_engine_rpm_block;
|
||||
delete from mmt_staging2.stg_specific_table_ftdry_trs;
|
||||
delete from mmt_staging2.stg_process_table_ftdry_trs;
|
||||
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_number_start=null,
|
||||
row_previous_number=null,
|
||||
row_read_end=null,
|
||||
run_time=null
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
|
||||
execute 'insert into mmt_staging2.stg_specific_table_ftdry_trs
|
||||
select * from mmt_staging1.mmt_staging_generic_table a
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
and a.file_syspk='||p_file_syspk||'';
|
||||
|
||||
update mmt_staging2.stg_specific_table_ftdry_trs set column2 = TRIM (TRAILING FROM column2 );
|
||||
update mmt_staging2.stg_specific_table_ftdry_trs set column2 = TRIM (LEADING FROM column2 );
|
||||
|
||||
|
||||
update mmt_ods.mmt_config set F1_modified = TRIM (TRAILING FROM F1_modified);
|
||||
update mmt_ods.mmt_config set F1_modified = TRIM (LEADING FROM F1_modified);
|
||||
update mmt_ods.mmt_config set F1_source=F1_modified;
|
||||
update mmt_ods.mmt_config set F1_source = TRIM (TRAILING FROM F1_source) ;
|
||||
update mmt_ods.mmt_config set F1_source = TRIM (LEADING FROM F1_source);
|
||||
|
||||
/* updating mmt_config*/
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_number_start=(select min(b.row_number)
|
||||
from mmt_staging2.stg_specific_table_ftdry_trs b
|
||||
where trim(upper(F1_source))= trim(upper(column2))
|
||||
and b.is_rownumber_fetched is null)
|
||||
where a.row_number_start is null and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_staging2.stg_specific_table_ftdry_trs a
|
||||
set is_rownumber_fetched=1
|
||||
from mmt_ods.mmt_config b
|
||||
where trim(upper(F1_source))= trim(upper(column2))
|
||||
and b.row_number_start=a.row_number
|
||||
and is_rownumber_fetched is null and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_ods.mmt_config a set row_previous_number=row_number_start-1
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_read_end= (select b.row_number_start
|
||||
from mmt_ods.mmt_config b
|
||||
where b.syspk=a.syspk+1 )
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_ods.mmt_config a set row_read_end = null
|
||||
where f1_modified =''Implement Details'' and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set run_time=current_timestamp
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
/*rank tags*/
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_ftdry_trs
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_ftdry_trs a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Tractor Specifications Sheet''
|
||||
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_ftdry_trs
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_ftdry_trs a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Tractor Specifications'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_ftdry_trs
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_ftdry_trs a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Engine RPM Data:'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_ftdry_trs
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_ftdry_trs a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >row_number_start
|
||||
and a.column2 <> ''''
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Implement Details'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
|
||||
|
||||
/*insert data into h1_int */
|
||||
|
||||
|
||||
insert into mmt_staging2.FTDRY_TRS_H1_INT(column2,column3,column4,column5,column6,column7)
|
||||
select column2,column3,column4,column5,column6,column7 from mmt_staging2.stg_process_table_ftdry_trs a where rank_tag='FTDRY_TRS_H1';
|
||||
|
||||
insert into mmt_staging2.FTDRY_TRS_H1_INT(column2) values ('Date of Test');
|
||||
|
||||
insert into mmt_staging2.FTDRY_TRS_H1_INT(column2) values ('Report Date');
|
||||
|
||||
insert into mmt_staging2.FTDRY_TRS_H1_INT(column2) values ('Season');
|
||||
|
||||
insert into mmt_staging2.FTDRY_TRS_H1_INT (column2) values ('Type of Soil');
|
||||
|
||||
insert into mmt_staging2.FTDRY_TRS_H1_INT (column2) values ('Soil Cone Index (kPa)');
|
||||
|
||||
insert into mmt_staging2.FTDRY_TRS_H1_INT (column2) values ('Field Condition');
|
||||
|
||||
|
||||
update mmt_staging2.FTDRY_TRS_H1_INT a
|
||||
set column3=(select column5 from mmt_staging2.FTDRY_TRS_H1_INT b
|
||||
where trim(a.column2)=trim(b.column4)
|
||||
and b.column4='Date of Test')
|
||||
where a.column2='Date of Test';
|
||||
|
||||
|
||||
update mmt_staging2.FTDRY_TRS_H1_INT a
|
||||
set column3=(select column7 from mmt_staging2.FTDRY_TRS_H1_INT b
|
||||
where trim(a.column2)=trim(b.column6)
|
||||
and b.column6='Report Date')
|
||||
where a.column2='Report Date';
|
||||
|
||||
update mmt_staging2.FTDRY_TRS_H1_INT a
|
||||
set column3=(select column6 from mmt_staging2.FTDRY_TRS_H1_INT b
|
||||
where trim(a.column2)=trim(b.column5)
|
||||
and b.column5='Season')
|
||||
where a.column2='Season';
|
||||
|
||||
update mmt_staging2.FTDRY_TRS_H1_INT a
|
||||
set column3=(select column6 from mmt_staging2.FTDRY_TRS_H1_INT b
|
||||
where trim(a.column2)=trim(b.column5)
|
||||
and b.column5='Type of Soil')
|
||||
where a.column2='Type of Soil';
|
||||
|
||||
|
||||
update mmt_staging2.FTDRY_TRS_H1_INT a
|
||||
set column3=(select column6 from mmt_staging2.FTDRY_TRS_H1_INT b
|
||||
where trim(a.column2)=trim(b.column5)
|
||||
and b.column5='Soil Cone Index (kPa)')
|
||||
where a.column2='Soil Cone Index (kPa)';
|
||||
|
||||
|
||||
update mmt_staging2.FTDRY_TRS_H1_INT a
|
||||
set column3=(select column6 from mmt_staging2.FTDRY_TRS_H1_INT b
|
||||
where trim(a.column2)=trim(b.column5)
|
||||
and b.column5='Field Condition')
|
||||
where a.column2='Field Condition';
|
||||
|
||||
|
||||
/*inserting data into block statements*/
|
||||
|
||||
insert into mmt_staging2.FTDRY_TRS_H1_Block
|
||||
(
|
||||
dummy_f,
|
||||
Report_Reference_No,
|
||||
Objective_Of_Test,
|
||||
Background_of_Test,
|
||||
Job_Order_No,
|
||||
Test_Location,
|
||||
Soil_Moisture_Content_,
|
||||
Soil_Bulk_Density_g_cc,
|
||||
Test_Engineer,
|
||||
Test_Operator,
|
||||
Date_of_Test,
|
||||
Report_Date,
|
||||
Season,
|
||||
Type_of_Soil,
|
||||
Soil_Cone_Index_kPa,
|
||||
Field_Condition
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text]) AS val
|
||||
FROM mmt_staging2.FTDRY_TRS_H1_INT
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text,
|
||||
a_11 text,a_12 text,a_13 text,a_14 text,a_15 text);
|
||||
|
||||
delete from mmt_staging2.FTDRY_TRS_H1_Block where dummy_f is null ;
|
||||
execute 'update mmt_staging2.FTDRY_TRS_H1_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
insert into mmt_staging2.FTDRY_TRS_SPEC_Block
|
||||
(
|
||||
dummy_f,
|
||||
Tractor_Model,
|
||||
Tractor_Make,
|
||||
Tractor_Sr_No,
|
||||
Tractor_Engine_HP,
|
||||
FIP_Type,
|
||||
hour_Meter_Reading,
|
||||
Steering_Type,
|
||||
Transmission_Type,
|
||||
Wheel_Drive_Type_WD,
|
||||
EGR_Yes_No,
|
||||
Brake_Type,
|
||||
PTO_Type,
|
||||
Standard_PTO_Speed_RPM,
|
||||
EPTO_Speed_RPM,
|
||||
Front_Tyre_Make,
|
||||
Front_Tyre_Size,
|
||||
Front_Tyre_Pressure_psi,
|
||||
Rear_Tyre_Make,
|
||||
Rear_Tyre_Size,
|
||||
Rear_Tyre_Pressure_psi ,
|
||||
Tractor_Weight_kg_Front ,
|
||||
Tractor_Weight_kg_Rear ,
|
||||
Tractor_Weight_kg_Total,
|
||||
Ballasted_Tractor_Accessories,
|
||||
Mechanical_Ballast_Rear,
|
||||
Mechanical_Ballast_Rear_in_KG ,
|
||||
Water_Ballast_Rear,
|
||||
Mechanical_Ballast_Front,
|
||||
Mechanical_Ballast_Front_in_Kg,
|
||||
Total_Ballast_Weight
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text]) AS val
|
||||
FROM mmt_staging2.stg_process_table_ftdry_trs where rank_tag=''FTDRY_TRS_SPEC''
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,
|
||||
a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text,a_21 text,
|
||||
a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text);
|
||||
|
||||
|
||||
delete from mmt_staging2.FTDRY_TRS_SPEC_Block where dummy_f is null ;
|
||||
execute 'update mmt_staging2.FTDRY_TRS_SPEC_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
insert into mmt_staging2.FTDRY_TRS_Engine_RPM_Block
|
||||
(
|
||||
dummy_f,
|
||||
tractor_model,
|
||||
tractor_make,
|
||||
Low_Idle,
|
||||
High_Idle,
|
||||
Rated_RPM,
|
||||
Engine_to_PTO_Ratio_540_PTO,
|
||||
Engine_to_PTO_Ratio_540E_PTO
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text]) AS val
|
||||
FROM mmt_staging2.stg_process_table_ftdry_trs where rank_tag=''FTDRY_TRS_Engine_RPM''
|
||||
or (rank_tag=''FTDRY_TRS_SPEC'' and rank in (1,2))
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text);
|
||||
|
||||
|
||||
delete from mmt_staging2.FTDRY_TRS_Engine_RPM_Block where dummy_f is null ;
|
||||
execute 'update mmt_staging2.FTDRY_TRS_Engine_RPM_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
|
||||
insert into mmt_staging2.FTDRY_TRS_Implement_Block
|
||||
(
|
||||
dummy_f,
|
||||
Name_of_Implement,
|
||||
Type_of_Implement,
|
||||
Make_of_Implement,
|
||||
No_of_bottoms_Tyne_Disc_Blade,
|
||||
Cutting_Width_m,
|
||||
Implement_Weight_Kg,
|
||||
Hitch_Category,
|
||||
Span_cm_For_Mounted_Implement,
|
||||
Mast_Height_cm_For_Mounted_Implement,
|
||||
FDPD_TDC_Mar15_008
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3,column4,column5,column6}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text]) AS val
|
||||
FROM mmt_staging2.stg_process_table_ftdry_trs where rank_tag=''FTDRY_TRS_Implement''
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t ( col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text
|
||||
,a_10 text);
|
||||
|
||||
|
||||
delete from mmt_staging2.FTDRY_TRS_Implement_Block where dummy_f is null ;
|
||||
execute 'update mmt_staging2.FTDRY_TRS_Implement_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
end
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
|
||||
select mmt_staging2.fn_FTDRY_TRS_Block(20,1,'FTDRY','FTDRY_TRS',179);
|
||||
403
Deepthi_SQL/execute functions/hlg_sum_execute.sql
Normal file
403
Deepthi_SQL/execute functions/hlg_sum_execute.sql
Normal file
@@ -0,0 +1,403 @@
|
||||
drop function if exists mmt_staging2.fn_FTHLG_SUM_Block ;
|
||||
CREATE OR REPLACE FUNCTION mmt_staging2.fn_FTHLG_SUM_Block(p_client_id int,p_function_id int, p_file_format text,
|
||||
p_sheet_mnemonic text, p_file_syspk int)
|
||||
RETURNS void AS $$
|
||||
begin
|
||||
SET search_path TO mmt_staging2;
|
||||
delete from mmt_staging2.FTHLG_SUM_Trac_H1_Block;
|
||||
delete from mmt_staging2.FTHLG_SUM_Trail_Type_Block;
|
||||
delete from mmt_staging2.FTHLG_SUM_Test_Condition_1_Block;
|
||||
delete from mmt_staging2.FTHLG_SUM_Test_Condition_2_Block;
|
||||
delete from mmt_staging2.FTHLG_SUM_Comments_By_Block;
|
||||
delete from mmt_staging2.stg_specific_table_fthlg_sum;
|
||||
delete from mmt_staging2.stg_process_table_fthlg_sum;
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_number_start=null,
|
||||
row_previous_number=null,
|
||||
row_read_end=null,
|
||||
run_time=null
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_specific_table_fthlg_sum
|
||||
select * from mmt_staging1.mmt_staging_generic_table a
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
and a.file_syspk='||p_file_syspk||'';
|
||||
|
||||
update mmt_staging2.stg_specific_table_fthlg_sum set column2 = TRIM (TRAILING FROM column2 );
|
||||
update mmt_staging2.stg_specific_table_fthlg_sum set column2 = TRIM (LEADING FROM column2 );
|
||||
|
||||
|
||||
update mmt_ods.mmt_config set F1_modified = TRIM (TRAILING FROM F1_modified);
|
||||
update mmt_ods.mmt_config set F1_modified = TRIM (LEADING FROM F1_modified) ;
|
||||
update mmt_ods.mmt_config set F1_source=F1_modified ;
|
||||
update mmt_ods.mmt_config set F1_source = TRIM (TRAILING FROM F1_source) ;
|
||||
update mmt_ods.mmt_config set F1_source = TRIM (LEADING FROM F1_source) ;
|
||||
|
||||
execute 'update mmt_ods.mmt_config a set f1_source = replace(f1_source,''_1'','''')
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_number_start=(select min(b.row_number)
|
||||
from mmt_staging2.stg_specific_table_fthlg_sum b
|
||||
where F1_source=column2
|
||||
and b.is_rownumber_fetched is null)
|
||||
where a.row_number_start is null
|
||||
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_staging2.stg_specific_table_fthlg_sum a
|
||||
set is_rownumber_fetched=1
|
||||
from mmt_ods.mmt_config b
|
||||
where F1_source=column2
|
||||
and b.row_number_start=a.row_number
|
||||
and is_rownumber_fetched is null
|
||||
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_ods.mmt_config a set f1_source = replace(f1_source,''_2'','''')
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_number_start=(select min(b.row_number)
|
||||
from mmt_staging2.stg_specific_table_fthlg_sum b
|
||||
where F1_source=column2
|
||||
and b.is_rownumber_fetched is null)
|
||||
where a.row_number_start is null
|
||||
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_staging2.stg_specific_table_fthlg_sum a
|
||||
set is_rownumber_fetched=1
|
||||
from mmt_ods.mmt_config b
|
||||
where F1_source=column2
|
||||
and b.row_number_start=a.row_number
|
||||
and is_rownumber_fetched is null and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_ods.mmt_config a set row_previous_number=row_number_start-1
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_read_end= (select b.row_number_start
|
||||
from mmt_ods.mmt_config b
|
||||
where b.syspk=a.syspk+1 )
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_ods.mmt_config a set row_read_end = null where f1_modified =''Test Manager Comments_2'' and
|
||||
a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set run_time=current_timestamp
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_fthlg_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_fthlg_sum a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Objective Of Test''
|
||||
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_fthlg_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_fthlg_sum a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Trailer Type''
|
||||
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_fthlg_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_fthlg_sum a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Condition_1:''
|
||||
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_fthlg_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_fthlg_sum a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Engineer Comments_1''
|
||||
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_fthlg_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_fthlg_sum a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Manager Comments_1''
|
||||
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_fthlg_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_fthlg_sum a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Condition_2:''
|
||||
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_fthlg_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_fthlg_sum a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Engineer Comments_2''
|
||||
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_fthlg_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_fthlg_sum a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Manager Comments_2''
|
||||
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
|
||||
|
||||
insert into mmt_staging2.FTHLG_SUM_Trac_H1_Block
|
||||
(
|
||||
tractor_model,
|
||||
tractor_make ,
|
||||
tractor_engine_hp,
|
||||
rated_rpm,
|
||||
transmission_type,
|
||||
wheel_drive_type,
|
||||
fip_type,
|
||||
steering_type,
|
||||
tractor_weight_kg_front,
|
||||
tractor_weight_kg_rear,
|
||||
tractor_weight_kg_total
|
||||
)
|
||||
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12
|
||||
from mmt_staging2.stg_process_table_fthlg_sum
|
||||
where rank_tag='FTHLG_SUM_Trac_H1' and rank <> 1;
|
||||
|
||||
|
||||
--delete from mmt_staging2.FTHLG_SUM_Trac_H1_Block where dummy_f is null ;
|
||||
execute 'update mmt_staging2.FTHLG_SUM_Trac_H1_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
|
||||
|
||||
insert into mmt_staging2.FTHLG_SUM_Trail_Type_Block
|
||||
(
|
||||
Trailer_Type,
|
||||
Tire_size_and_inflation_pressure_psi,
|
||||
No_Of_Axle,
|
||||
No_Of_Wheels,
|
||||
Trailer_Gross_Weight_Kg,
|
||||
Tractor_Rear_Wheel_Center_to_Hitch_Point_Center_Distance_mm,
|
||||
Tractor_Hitch_Height_from_Ground_mm,
|
||||
Trailer_hitch_Height_above_ground_level_mm,
|
||||
Gradient_Slope_1_Degree,
|
||||
Gradient_Slope_2_degree,
|
||||
Tractor_Hitch_Type
|
||||
)
|
||||
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12
|
||||
from mmt_staging2.stg_process_table_fthlg_sum
|
||||
where rank_tag='FTHLG_SUM_Trail_Type' and rank <> 1;
|
||||
|
||||
|
||||
--delete from mmt_staging2.FTHLG_SUM_Trail_Type_Block where dummy_f is null ;
|
||||
execute 'update mmt_staging2.FTHLG_SUM_Trail_Type_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
|
||||
insert into mmt_staging2.FTHLG_SUM_Test_Condition_1_Block
|
||||
(
|
||||
dummy_f,
|
||||
Test_Condition,
|
||||
Test_Date,
|
||||
Tractor_Model,
|
||||
Fuel_consumption_Ltr_hr,
|
||||
Mileage_Km_Ltr,
|
||||
Average_speed_of_travel_kmph,
|
||||
Total_distance_travelled_km,
|
||||
Gear_used_on_Straight_Road,
|
||||
Straight_road_RPM_Drop,
|
||||
Gear_used_on_Up_Slope_1,
|
||||
Up_Slope_RPM_Drop_1,
|
||||
Gear_used_on_Up_Slope_2,
|
||||
Up_Slope_RPM_Drop_2,
|
||||
Gear_used_on_Down_Slope,
|
||||
Down_Slope_RPM_Shoot_up,
|
||||
M_M_Performance_compared_to_respective_competitor_tractors_is_better_and_is_poor_than_competitor,
|
||||
Fuel_consumption_lit_hr_2,
|
||||
Mileage_Km_Ltr_2,
|
||||
M_M_Performance_in_compared_to_respective_competitor_tractors,
|
||||
Fuel_consumption_lit_hr_3,
|
||||
Mileage_Km_Ltr_3,
|
||||
Engine_Smoke_on_Load,
|
||||
Engine_acceleration_smoke,
|
||||
Range_Gear_Shifting,
|
||||
Speed_Gear_Shifting,
|
||||
Tractor_Steer_ability,
|
||||
Tractor_braking_performance,
|
||||
Front_Visibility,
|
||||
Implement_Accessibility,
|
||||
Front_end_lifting_during_operation,
|
||||
RPM_Recovery_Time,
|
||||
Engine_Vibration,
|
||||
Engine_Sound
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3,column4,column5,column6,column7,column8,column9,column10,column11,column12}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text,
|
||||
column4::text,column5::text,column6::text,column7::text,column8::text,
|
||||
column9::text,column10::text,column11::text,column12::text]) AS val
|
||||
FROM mmt_staging2.stg_process_table_fthlg_sum where rank_tag=''FTHLG_SUM_Test_Condition_1''
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text,
|
||||
a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text
|
||||
,a_21 text,a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text,
|
||||
a_31 text,a_32 text,a_33 text);
|
||||
|
||||
|
||||
delete from mmt_staging2.FTHLG_SUM_Test_Condition_1_Block where dummy_f is null ;
|
||||
execute 'update mmt_staging2.FTHLG_SUM_Test_Condition_1_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
|
||||
insert into mmt_staging2.FTHLG_SUM_Test_Condition_2_Block
|
||||
(
|
||||
dummy_f,
|
||||
Test_Condition,
|
||||
Test_Date,
|
||||
Tractor_Model,
|
||||
Fuel_consumption_Ltr_hr,
|
||||
Mileage_Km_Ltr,
|
||||
Average_speed_of_travel_kmph,
|
||||
Total_distance_travelled_km,
|
||||
Gear_used_on_Straight_Road,
|
||||
Straight_road_RPM_Drop,
|
||||
Gear_used_on_Up_Slope_1,
|
||||
Up_Slope_RPM_Drop_1,
|
||||
Gear_used_on_Up_Slope_2,
|
||||
Up_Slope_RPM_Drop_2,
|
||||
Gear_used_on_Down_Slope,
|
||||
Down_Slope_RPM_Shoot_up,
|
||||
M_M_Performance_compared_to_respective_competitor_tractors_is_better_and_is_poor_than_competitor,
|
||||
Fuel_consumption_lit_hr_2,
|
||||
Mileage_Km_Ltr_2,
|
||||
M_M_Performance_in_compared_to_respective_competitor_tractors,
|
||||
Fuel_consumption_lit_hr_3,
|
||||
Mileage_Km_Ltr_3,
|
||||
Engine_Smoke_on_Load,
|
||||
Engine_acceleration_smoke,
|
||||
Range_Gear_Shifting,
|
||||
Speed_Gear_Shifting,
|
||||
Tractor_Steer_ability,
|
||||
Tractor_braking_performance,
|
||||
Front_Visibility,
|
||||
Implement_Accessibility,
|
||||
Front_end_lifting_during_operation,
|
||||
RPM_Recovery_Time,
|
||||
Engine_Vibration,
|
||||
Engine_Sound
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3,column4,column5,column6,column7,column8,column9,column10,column11,column12}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text,column8::text,column9::text,column10::text,column11::text,column12::text]) AS val
|
||||
FROM mmt_staging2.stg_process_table_fthlg_sum where rank_tag=''FTHLG_SUM_Test_Condition_2''
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,
|
||||
a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text,a_21 text,
|
||||
a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text,a_31 text
|
||||
,a_32 text,a_33 text);
|
||||
|
||||
|
||||
delete from mmt_staging2.FTHLG_SUM_Test_Condition_2_Block where dummy_f is null ;
|
||||
execute 'update mmt_staging2.FTHLG_SUM_Test_Condition_2_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
|
||||
insert into mmt_staging2.FTHLG_SUM_Comments_By_Block (dummy_f) values
|
||||
('dummy');
|
||||
|
||||
execute 'update mmt_staging2.FTHLG_SUM_Comments_By_Block set test_engineer_comments_1=
|
||||
(select column3 from mmt_staging2.stg_process_table_fthlg_sum a
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
and a.rank_tag=''FTHLG_SUM_Engineer_Comments_1''
|
||||
and rank=1 ) where dummy_f=''dummy''' ;
|
||||
|
||||
execute 'update mmt_staging2.FTHLG_SUM_Comments_By_Block set test_engineer_comments_2=
|
||||
(select column3 from mmt_staging2.stg_process_table_fthlg_sum a
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
and a.rank_tag=''FTHLG_SUM_Engineer_Comments_2''
|
||||
and rank=1 ) where dummy_f=''dummy''';
|
||||
|
||||
execute 'update mmt_staging2.FTHLG_SUM_Comments_By_Block set test_manager_comments_1=
|
||||
(select column3 from mmt_staging2.stg_process_table_fthlg_sum a
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
and a.rank_tag=''FTHLG_SUM_Manager_Comments_1''
|
||||
and rank=1 ) where dummy_f=''dummy''';
|
||||
|
||||
execute 'update mmt_staging2.FTHLG_SUM_Comments_By_Block set test_manager_comments_2=
|
||||
(select column3 from mmt_staging2.stg_process_table_fthlg_sum a
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
and a.rank_tag=''FTHLG_SUM_Manager_Comments_2''
|
||||
and rank=1 ) where dummy_f=''dummy''';
|
||||
|
||||
|
||||
|
||||
delete from mmt_staging2.FTHLG_SUM_Comments_By_Block where dummy_f is null ;
|
||||
|
||||
execute 'update mmt_staging2.FTHLG_SUM_Comments_By_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
end
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
select mmt_staging2.fn_FTHLG_SUM_Block(20,1,'FTHLG','FTHLG_SUM',180)
|
||||
|
||||
|
||||
331
Deepthi_SQL/execute functions/hlg_trs_execute.sql
Normal file
331
Deepthi_SQL/execute functions/hlg_trs_execute.sql
Normal file
@@ -0,0 +1,331 @@
|
||||
drop function if exists mmt_staging2.fn_fthlg_trs_block;
|
||||
CREATE OR REPLACE FUNCTION mmt_staging2.fn_fthlg_trs_block(p_client_id int,p_function_id int, p_file_format text,
|
||||
p_sheet_mnemonic text, p_file_syspk int)
|
||||
RETURNS void AS $$
|
||||
begin
|
||||
|
||||
|
||||
delete from mmt_staging2.FTHLG_TRS_H1_INT;
|
||||
delete from mmt_staging2.FTHLG_TRS_H1_Block;
|
||||
delete from mmt_staging2.FTHLG_TRS_SPEC_Block;
|
||||
delete from mmt_staging2.FTHLG_TRS_Engine_RPM_Block;
|
||||
delete from mmt_staging2.FTHLG_TRS_Trailer_Block;
|
||||
delete from mmt_staging2.stg_specific_table_fthlg_trs;
|
||||
delete from mmt_staging2.stg_process_table_fthlg_trs;
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_number_start=null,
|
||||
row_previous_number=null,
|
||||
row_read_end=null,
|
||||
run_time=null
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_specific_table_fthlg_trs
|
||||
select * from mmt_staging1.mmt_staging_generic_table a
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
and a.file_syspk='||p_file_syspk||'';
|
||||
|
||||
update mmt_staging2.stg_specific_table_fthlg_trs set column2 = TRIM (TRAILING FROM column2 );
|
||||
update mmt_staging2.stg_specific_table_fthlg_trs set column2 = TRIM (LEADING FROM column2 );
|
||||
|
||||
|
||||
|
||||
update mmt_ods.mmt_config set F1_modified = TRIM (TRAILING FROM F1_modified);
|
||||
update mmt_ods.mmt_config set F1_modified = TRIM (LEADING FROM F1_modified);
|
||||
update mmt_ods.mmt_config set F1_source=F1_modified;
|
||||
update mmt_ods.mmt_config set F1_source = TRIM (TRAILING FROM F1_source);
|
||||
update mmt_ods.mmt_config set F1_source = TRIM (LEADING FROM F1_source);
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_number_start=(select min(b.row_number)
|
||||
from mmt_staging2.stg_specific_table_fthlg_trs b
|
||||
where F1_source=column2
|
||||
and b.is_rownumber_fetched is null)
|
||||
where a.row_number_start is null and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
execute 'update mmt_staging2.stg_specific_table_fthlg_trs a
|
||||
set is_rownumber_fetched=1
|
||||
from mmt_ods.mmt_config b
|
||||
where F1_source=column2
|
||||
and b.row_number_start=a.row_number
|
||||
and is_rownumber_fetched is null and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
execute 'update mmt_ods.mmt_config a set row_previous_number=row_number_start-1
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_read_end= (select b.row_number_start
|
||||
from mmt_ods.mmt_config b
|
||||
where b.syspk=a.syspk+1 )
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
execute 'update mmt_ods.mmt_config a set row_read_end = null where f1_modified =''Trailer Details'' and
|
||||
a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set run_time=current_timestamp where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_fthlg_trs
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_fthlg_trs a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Tractor specifications sheet'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_fthlg_trs
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_fthlg_trs a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Tractor Specifications'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_fthlg_trs
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_fthlg_trs a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Engine RPM Data:'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_fthlg_trs
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_fthlg_trs a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Trailer Details'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
delete from mmt_staging2.stg_process_table_fthlg_trs where row_number between 88 and 98;
|
||||
|
||||
insert into mmt_staging2.FTHLG_TRS_H1_INT(column2,column3,column4,column5,column6,column7)
|
||||
select column2,column3,column4,column5,column6,column7 from mmt_staging2.stg_process_table_fthlg_trs a
|
||||
where rank_tag='FTHLG_TRS_H1';
|
||||
|
||||
|
||||
insert into mmt_staging2.FTHLG_TRS_H1_INT(column2) values ('Date of Test');
|
||||
|
||||
insert into mmt_staging2.FTHLG_TRS_H1_INT(column2) values ('Report Date');
|
||||
|
||||
insert into mmt_staging2.FTHLG_TRS_H1_INT(column2) values ('Type of Road');
|
||||
|
||||
insert into mmt_staging2.FTHLG_TRS_H1_INT (column2) values ('Tractor Hitch Height from Ground, mm');
|
||||
|
||||
insert into mmt_staging2.FTHLG_TRS_H1_INT (column2) values ('Tractor Rear Wheel Center to Hitch Point Center Distance, mm');
|
||||
|
||||
|
||||
update mmt_staging2.FTHLG_TRS_H1_INT a
|
||||
set column3=(select column5 from mmt_staging2.FTHLG_TRS_H1_INT b
|
||||
where trim(a.column2)=trim(b.column4)
|
||||
and b.column4='Date of Test')
|
||||
where a.column2='Date of Test';
|
||||
|
||||
update mmt_staging2.FTHLG_TRS_H1_INT a
|
||||
set column3=(select column7 from mmt_staging2.FTHLG_TRS_H1_INT b
|
||||
where trim(a.column2)=trim(b.column6)
|
||||
and b.column6='Report Date')
|
||||
where a.column2='Report Date';
|
||||
|
||||
update mmt_staging2.FTHLG_TRS_H1_INT a
|
||||
set column3=(select column6 from mmt_staging2.FTHLG_TRS_H1_INT b
|
||||
where trim(a.column2)=trim(b.column5)
|
||||
and b.column5='Type of Road')
|
||||
where a.column2='Type of Road';
|
||||
|
||||
update mmt_staging2.FTHLG_TRS_H1_INT a
|
||||
set column3=(select column6 from mmt_staging2.FTHLG_TRS_H1_INT b
|
||||
where trim(a.column2)=trim(b.column5)
|
||||
and b.column5='Tractor Hitch Height from Ground, mm')
|
||||
where a.column2='Tractor Hitch Height from Ground, mm';
|
||||
|
||||
|
||||
update mmt_staging2.FTHLG_TRS_H1_INT a
|
||||
set column3=(select column6 from mmt_staging2.FTHLG_TRS_H1_INT b
|
||||
where trim(a.column2)=trim(b.column5)
|
||||
and b.column5='Tractor Rear Wheel Center to Hitch Point Center Distance, mm')
|
||||
where a.column2='Tractor Rear Wheel Center to Hitch Point Center Distance, mm';
|
||||
|
||||
|
||||
insert into mmt_staging2.FTHLG_TRS_H1_Block
|
||||
(
|
||||
dummy_f,
|
||||
Report_Reference_No,
|
||||
Objective_Of_Test,
|
||||
Background_of_Test,
|
||||
Job_Order_No,
|
||||
Test_Location,
|
||||
Gradient_Slope_1_Degree,
|
||||
Gradient_Slope_2_Degree,
|
||||
Tractor_Hitch_Type,
|
||||
Test_Engineer,
|
||||
Test_Operator,
|
||||
Date_of_Test,
|
||||
Report_Date,
|
||||
Type_of_Road,
|
||||
Tractor_Hitch_Height_from_Ground_mm,
|
||||
Tractor_Rear_Wheel_Center_to_Hitch_Point_Center_Distance_mm
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text]) AS val
|
||||
FROM mmt_staging2.FTHLG_TRS_H1_INT
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text,
|
||||
a_11 text,a_12 text,a_13 text,a_14 text,a_15 text);
|
||||
|
||||
|
||||
delete from mmt_staging2.FTHLG_TRS_H1_Block where dummy_f is null ;
|
||||
execute 'update mmt_staging2.FTHLG_TRS_H1_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
insert into mmt_staging2.FTHLG_TRS_SPEC_Block
|
||||
(
|
||||
dummy_f,
|
||||
Tractor_Model,
|
||||
Tractor_Make,
|
||||
Tractor_Sr_No,
|
||||
Tractor_Engine_HP,
|
||||
FIP_Type,
|
||||
hour_Meter_Reading,
|
||||
Steering_Type,
|
||||
Transmission_Type,
|
||||
Wheel_Drive_Type_WD,
|
||||
EGR_Yes_No,
|
||||
Brake_Type,
|
||||
PTO_Type,
|
||||
Standard_PTO_Speed_RPM,
|
||||
EPTO_Speed_RPM,
|
||||
Front_Tyre_Make,
|
||||
Front_Tyre_Size,
|
||||
Front_Tyre_Pressure_psi,
|
||||
Rear_Tyre_Make,
|
||||
Rear_Tyre_Size,
|
||||
Rear_Tyre_Pressure_psi ,
|
||||
Tractor_Weight_kg_Front ,
|
||||
Tractor_Weight_kg_Rear ,
|
||||
Tractor_Weight_kg_Total,
|
||||
Ballasted_Tractor_Accessories,
|
||||
Mechanical_Ballast_Rear,
|
||||
Mechanical_Ballast_Rear_in_KG ,
|
||||
Water_Ballast_Rear_75,
|
||||
Mechanical_Ballast_Front_in_Kg,
|
||||
Mechanical_Ballast_Front,
|
||||
Total_Ballast_Weight
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text]) AS val
|
||||
FROM mmt_staging2.stg_process_table_fthlg_trs where rank_tag=''FTHLG_TRS_SPEC''
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,
|
||||
a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text,a_21 text,
|
||||
a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text);
|
||||
|
||||
|
||||
delete from mmt_staging2.FTHLG_TRS_SPEC_Block where dummy_f is null ;
|
||||
execute 'update mmt_staging2.FTHLG_TRS_SPEC_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
insert into mmt_staging2.FTHLG_TRS_Engine_RPM_Block
|
||||
(
|
||||
dummy_f,
|
||||
Tractor_model,
|
||||
Tractor_make,
|
||||
Low_Idle,
|
||||
High_Idle,
|
||||
Rated_RPM,
|
||||
Engine_to_PTO_Ratio_540_PTO,
|
||||
Engine_to_PTO_Ratio_540E_PTO
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text]) AS val
|
||||
FROM mmt_staging2.stg_process_table_fthlg_trs where rank_tag=''FTHLG_TRS_Engine_RPM''
|
||||
or (rank_tag=''FTHLG_TRS_SPEC'' and rank in (1,2))
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text);
|
||||
|
||||
|
||||
delete from mmt_staging2.FTHLG_TRS_Engine_RPM_Block where dummy_f is null ;
|
||||
execute 'update mmt_staging2.FTHLG_TRS_Engine_RPM_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
insert into mmt_staging2.FTHLG_TRS_Trailer_Block
|
||||
(
|
||||
dummy_f,
|
||||
Type_Of_Trailer,
|
||||
No_Of_Axle,
|
||||
No_Of_Wheels,
|
||||
Trailer_hitch_Height_above_ground_level_mm,
|
||||
Make_model_of_trailer,
|
||||
Trailer_platform_length_mm,
|
||||
Trailer_platform_Width_mm,
|
||||
Trailer_platform_Height_mm,
|
||||
Tire_size,
|
||||
Inflation_pressure_psi,
|
||||
Track_width_of_trailer_mm,
|
||||
Horizontal_distance_of_hitch_point_from_trailer_front_face_mm,
|
||||
Tractor_Rear_Wheel_Center_to_Hitch_Point_Center_Distance_mm,
|
||||
Distance_from_Trailerfront_axle_distance_from_hitch_point_mm,
|
||||
Distance_from_tractor_rear_wheel_center_to_tractor_rear_wheel_center_mm,
|
||||
Trailer_empty_weight_Kg,
|
||||
Trailer_Gross_Weight_Kg,
|
||||
FDPD_TDC_Mar15_009
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3,column4,column5,column6}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text]) AS val
|
||||
FROM mmt_staging2.stg_process_table_fthlg_trs where rank_tag=''FTHLG_TRS_Trailer''
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t ( col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text
|
||||
,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text);
|
||||
|
||||
delete from mmt_staging2.FTHLG_TRS_Trailer_Block where dummy_f is null ;
|
||||
execute 'update mmt_staging2.FTHLG_TRS_Trailer_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
end
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
select mmt_staging2.fn_fthlg_trs_block(20,1,'FTHLG','FTHLG_TRS',180)
|
||||
|
||||
|
||||
289
Deepthi_SQL/execute functions/wet_sum_execute.sql
Normal file
289
Deepthi_SQL/execute functions/wet_sum_execute.sql
Normal file
@@ -0,0 +1,289 @@
|
||||
drop function if exists mmt_staging2.fn_FTWET_SUM_Block ;
|
||||
CREATE OR REPLACE FUNCTION mmt_staging2.fn_FTWET_SUM_Block(p_client_id int,p_function_id int, p_file_format text,
|
||||
p_sheet_mnemonic text, p_file_syspk int)
|
||||
RETURNS void AS $$
|
||||
begin
|
||||
|
||||
SET search_path TO mmt_staging2;
|
||||
delete from mmt_staging2.FTWET_SUM_Trac_H1_Block;
|
||||
delete from mmt_staging2.FTWET_SUM_Implement_Block;
|
||||
delete from mmt_staging2.FTWET_SUM_Cage_Wheel_Block;
|
||||
delete from mmt_staging2.FTWET_SUM_Test_Condition_Block;
|
||||
delete from mmt_staging2.FTWET_SUM_Comments_By_Block;
|
||||
delete from mmt_staging2.stg_specific_table_ftwet_sum;
|
||||
delete from mmt_staging2.stg_process_table_ftwet_sum;
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_number_start=null,
|
||||
row_previous_number=null,
|
||||
row_read_end=null,
|
||||
run_time=null
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_specific_table_ftwet_sum
|
||||
select * from mmt_staging1.mmt_staging_generic_table a
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
and a.file_syspk='||p_file_syspk||'';
|
||||
|
||||
|
||||
update mmt_staging2.stg_specific_table_ftwet_sum set column2 = TRIM (TRAILING FROM column2 );
|
||||
update mmt_staging2.stg_specific_table_ftwet_sum set column2 = TRIM (LEADING FROM column2 );
|
||||
|
||||
|
||||
update mmt_ods.mmt_config set F1_modified = TRIM (TRAILING FROM F1_modified);
|
||||
update mmt_ods.mmt_config set F1_modified = TRIM (LEADING FROM F1_modified) ;
|
||||
update mmt_ods.mmt_config set F1_source=F1_modified;
|
||||
update mmt_ods.mmt_config set F1_source = TRIM (TRAILING FROM F1_source);
|
||||
update mmt_ods.mmt_config set F1_source = TRIM (LEADING FROM F1_source);
|
||||
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_number_start=(select min(b.row_number)
|
||||
from mmt_staging2.stg_specific_table_ftwet_sum b
|
||||
where F1_source=column2
|
||||
and b.is_rownumber_fetched is null)
|
||||
where a.row_number_start is null
|
||||
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_staging2.stg_specific_table_ftwet_sum a
|
||||
set is_rownumber_fetched=1
|
||||
from mmt_ods.mmt_config b
|
||||
where F1_source=column2
|
||||
and b.row_number_start=a.row_number
|
||||
and is_rownumber_fetched is null and
|
||||
a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
execute 'update mmt_ods.mmt_config a set row_previous_number=row_number_start-1
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_read_end= (select b.row_number_start
|
||||
from mmt_ods.mmt_config b
|
||||
where b.syspk=a.syspk+1 )
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_ods.mmt_config a set row_read_end = null where f1_modified =''Test Manager Comments'' and
|
||||
a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set run_time=current_timestamp
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_ftwet_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_ftwet_sum a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Tractor Model'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_ftwet_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_ftwet_sum a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Make of Implement'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_ftwet_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_ftwet_sum a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Type of Cage Wheel'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_ftwet_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_ftwet_sum a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Condition:'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_ftwet_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_ftwet_sum a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Manager Comments'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
insert into mmt_staging2.FTWET_SUM_Trac_H1_Block
|
||||
(
|
||||
Tractor_Model,
|
||||
Tractor_Make,
|
||||
Tractor_Engine_HP,
|
||||
Rated_RPM,
|
||||
Transmission_Type,
|
||||
Wheel_Drive_Type,
|
||||
FIP_Type,
|
||||
Steering_Type,
|
||||
Tractor_Weight_kg_Front,
|
||||
Tractor_Weight_kg_Rear,
|
||||
Tractor_Weight_kg_Total
|
||||
)
|
||||
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12
|
||||
from mmt_staging2.stg_process_table_FTWET_sum
|
||||
where rank_tag='FTWET_SUM_Trac_H1' and rank <> 1;
|
||||
|
||||
/*delete from mmt_staging2.FTWET_SUM_Trac_H1_Block where dummy_f is null ; */
|
||||
execute 'update mmt_staging2.FTWET_SUM_Trac_H1_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
insert into mmt_staging2.FTWET_SUM_Implement_Block
|
||||
(
|
||||
Make_of_Implement,
|
||||
Implement_Type,
|
||||
Implement_Size,
|
||||
Hitch_Category,
|
||||
Implement_Weight,
|
||||
Soil_Type,
|
||||
Moisture_Content ,
|
||||
Bulk_Density_g_cc ,
|
||||
Soil_Cone_index,
|
||||
Field_Condition ,
|
||||
Season
|
||||
)
|
||||
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12
|
||||
from mmt_staging2.stg_process_table_FTWET_sum
|
||||
where rank_tag='FTWET_SUM_Implement' and rank <> 1;
|
||||
|
||||
--delete from mmt_staging2.FTWET_SUM_Implement_Block where dummy_f is null ;
|
||||
|
||||
execute 'update mmt_staging2.FTWET_SUM_Implement_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
insert into mmt_staging2.FTWET_SUM_Cage_Wheel_Block
|
||||
(
|
||||
Type_of_Cage_Wheel,
|
||||
Cage_Wheel_Width_mm,
|
||||
Cage_wheel_Weight,
|
||||
Cage_Wheel_inner_Outer_Ring_Dia_mm,
|
||||
Cage_Wheel_Center_Ring_Dia_mm,
|
||||
Distance_between_RHS_LHS_cage_wheel_Inner_Ring_mm,
|
||||
No_of_angles_on_cage_wheel
|
||||
)
|
||||
select column2,column3,column4,column5,column6,column7,column8
|
||||
from mmt_staging2.stg_process_table_FTWET_sum
|
||||
where rank_tag='FTWET_SUM_Cage_Wheel' and rank not in (1,3);
|
||||
|
||||
|
||||
/*delete from mmt_staging2.FTWET_SUM_Cage_Wheel_Block where dummy_f is null ; */
|
||||
execute 'update mmt_staging2.FTWET_SUM_Cage_Wheel_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
insert into mmt_staging2.FTWET_SUM_Test_Condition_Block
|
||||
(
|
||||
dummy_f,
|
||||
Test_Condition,
|
||||
Test_Date,
|
||||
Tractor_Model,
|
||||
Engine_RPM_set,
|
||||
PTO_RPM_set,
|
||||
Gear_Used,
|
||||
Nominal_Speed_KMPH,
|
||||
Engine_RPM_Drop_on_straight_1st_Pass,
|
||||
Engine_RPM_Drop_on_straight_2nd_Pass,
|
||||
Engine_RPM_Drop_on_straight_3rd_Pass,
|
||||
Engine_RPM_Drop_on_turn_1st_Pass,
|
||||
Engine_RPM_Drop_on_turn_2nd_Pass,
|
||||
Engine_RPM_Drop_on_turn_3rd_Pass,
|
||||
No_of_passes,
|
||||
Avg_Depth_of_cut_cm,
|
||||
Fuel_consumption_lit_hr,
|
||||
Area_covered_acr_hr,
|
||||
Fuel_consumption_lit_Acr,
|
||||
M_M_Performance_in_compared_to_respective_competitor_tractors,
|
||||
Fuel_consumption_lit_hr_2,
|
||||
Area_covered_acr_hr_2,
|
||||
Fuel_consumption_lit_Acr_2,
|
||||
Trail_Observations,
|
||||
Engine_Smoke_on_Load,
|
||||
Engine_acceleration_smoke,
|
||||
Draft_Response,
|
||||
Tractor_Steer_ability,
|
||||
Tractor_braking_performance,
|
||||
Front_Visibility,
|
||||
Implement_Accessibility,
|
||||
Front_Wheel_dragging_at_turning,
|
||||
Front_end_lifting_during_operation,
|
||||
RPM_Recovery_Time,
|
||||
Engine_Vibration,
|
||||
Engine_Sound,
|
||||
Implement_Lifting_Lowering_response,
|
||||
Pulverization_Quality,
|
||||
Pulverization_Index
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3,column4,column5,column6,column7,column8,column9,column10,column11,column12}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text,
|
||||
column4::text,column5::text,column6::text,column7::text,column8::text,
|
||||
column9::text,column10::text,column11::text,column12::text]) AS val
|
||||
FROM mmt_staging2.stg_process_table_ftwet_sum where rank_tag=''FTWET_SUM_Test_Condition''
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t (ccol text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text,
|
||||
a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text
|
||||
,a_21 text,a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text,
|
||||
a_31 text,a_32 text,a_33 text,a_34 text,a_35 text,a_36 text,a_37 text,a_38 text);
|
||||
|
||||
|
||||
delete from mmt_staging2.FTWET_SUM_Test_Condition_Block where dummy_f is null ;
|
||||
execute 'update mmt_staging2.FTWET_SUM_Test_Condition_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
insert into mmt_staging2.FTWET_SUM_Comments_By_Block (dummy_f) values ('dummy');
|
||||
|
||||
|
||||
execute 'update mmt_staging2.FTWET_SUM_Comments_By_Block set test_manager_comments=
|
||||
(select column3 from mmt_staging2.stg_process_table_FTWET_sum a
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
and a.rank_tag=''FTWET_SUM_Manager_Comments''
|
||||
and a.rank=1 ) where dummy_f=''dummy''';
|
||||
|
||||
|
||||
delete from mmt_staging2.FTWET_SUM_Comments_By_Block where dummy_f is null ;
|
||||
execute 'update mmt_staging2.FTWET_SUM_Comments_By_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
end
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
select mmt_staging2.fn_FTWET_SUM_Block(20,1,'FTWET','FTWET_SUM',181)
|
||||
|
||||
|
||||
342
Deepthi_SQL/execute functions/wet_trs_execute.sql
Normal file
342
Deepthi_SQL/execute functions/wet_trs_execute.sql
Normal file
@@ -0,0 +1,342 @@
|
||||
|
||||
/*FTWET_TRS starts*/
|
||||
|
||||
drop function if exists mmt_staging2.fn_FTWET_TRS_Block ;
|
||||
CREATE OR REPLACE FUNCTION mmt_staging2.fn_FTWET_TRS_Block(p_client_id int,p_function_id int, p_file_format text,
|
||||
p_sheet_mnemonic text, p_file_syspk int)
|
||||
RETURNS void AS $$
|
||||
begin
|
||||
|
||||
SET search_path TO mmt_staging2;
|
||||
|
||||
delete from mmt_staging2.FTWET_TRS_H1_INT;
|
||||
delete from mmt_staging2.FTWET_TRS_H1_Block;
|
||||
delete from mmt_staging2.FTWET_TRS_Engine_RPM_Block;
|
||||
delete from mmt_staging2.FTWET_TRS_Implement_Block;
|
||||
delete from mmt_staging2.stg_specific_table_ftwet_trs;
|
||||
delete from mmt_staging2.stg_process_table_ftwet_trs;
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_number_start=null,
|
||||
row_previous_number=null,
|
||||
row_read_end=null,
|
||||
run_time=null
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_specific_table_ftwet_trs
|
||||
select * from mmt_staging1.mmt_staging_generic_table a
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
and a.file_syspk='||p_file_syspk||'';
|
||||
|
||||
update mmt_staging2.stg_specific_table_ftwet_trs set column2 = TRIM (TRAILING FROM column2 );
|
||||
update mmt_staging2.stg_specific_table_ftwet_trs set column2 = TRIM (LEADING FROM column2 );
|
||||
|
||||
|
||||
|
||||
update mmt_ods.mmt_config set F1_modified = TRIM (TRAILING FROM F1_modified);
|
||||
update mmt_ods.mmt_config set F1_modified = TRIM (LEADING FROM F1_modified);
|
||||
update mmt_ods.mmt_config set F1_source=F1_modified ;
|
||||
update mmt_ods.mmt_config set F1_source = TRIM (TRAILING FROM F1_source);
|
||||
update mmt_ods.mmt_config set F1_source = TRIM (LEADING FROM F1_source);
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_number_start=(select min(b.row_number)
|
||||
from mmt_staging2.stg_specific_table_ftwet_trs b
|
||||
where upper(trim(F1_source))=upper(trim(column2))
|
||||
and b.is_rownumber_fetched is null)
|
||||
where a.row_number_start is null
|
||||
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_staging2.stg_specific_table_ftwet_trs a
|
||||
set is_rownumber_fetched=1
|
||||
from mmt_ods.mmt_config b
|
||||
where upper(trim(F1_source))=upper(trim(column2))
|
||||
and b.row_number_start=a.row_number
|
||||
and is_rownumber_fetched is null
|
||||
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_ods.mmt_config a set row_previous_number=row_number_start-1
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set row_read_end= (select b.row_number_start
|
||||
from mmt_ods.mmt_config b
|
||||
where b.syspk=a.syspk+1 )
|
||||
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_ods.mmt_config a set row_read_end = null where f1_modified =''Implement Details''
|
||||
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update mmt_ods.mmt_config a
|
||||
set run_time=current_timestamp where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_ftwet_trs
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_ftwet_trs a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Tractor Specifications Sheet'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_ftwet_trs
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_ftwet_trs a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Tractor Specifications'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_ftwet_trs
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_ftwet_trs a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Engine RPM Data:'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into mmt_staging2.stg_process_table_ftwet_trs
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
|
||||
from mmt_staging2.stg_specific_table_ftwet_trs a
|
||||
join mmt_ods.mmt_config b
|
||||
on a.row_number >row_number_start
|
||||
and a.column2 <> ''''
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Implement Details'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
insert into mmt_staging2.FTWET_TRS_H1_INT(column2,column3,column4,column5,column6,column7)
|
||||
select column2,column3,column4,column5,column6,column7 from mmt_staging2.stg_process_table_ftwet_trs a
|
||||
where rank_tag='FTWET_TRS_H1';
|
||||
|
||||
|
||||
insert into mmt_staging2.FTWET_TRS_H1_INT(column2) values ('Date of Test');
|
||||
|
||||
insert into mmt_staging2.FTWET_TRS_H1_INT(column2) values ('Report Date');
|
||||
|
||||
insert into mmt_staging2.FTWET_TRS_H1_INT(column2) values ('Season');
|
||||
|
||||
insert into mmt_staging2.FTWET_TRS_H1_INT (column2) values ('Type of Soil');
|
||||
|
||||
insert into mmt_staging2.FTWET_TRS_H1_INT (column2) values ('Soil Cone Index (kPa)');
|
||||
|
||||
insert into mmt_staging2.FTWET_TRS_H1_INT (column2) values ('Field Condition');
|
||||
|
||||
update mmt_staging2.FTWET_TRS_H1_INT a
|
||||
set column3=(select column5 from mmt_staging2.FTWET_TRS_H1_INT b
|
||||
where trim(a.column2)=trim(b.column4)
|
||||
and b.column4='Date of Test')
|
||||
where a.column2='Date of Test';
|
||||
|
||||
update mmt_staging2.FTWET_TRS_H1_INT a
|
||||
set column3=(select column7 from mmt_staging2.FTWET_TRS_H1_INT b
|
||||
where trim(a.column2)=trim(b.column6)
|
||||
and b.column6='Report Date')
|
||||
where a.column2='Report Date';
|
||||
|
||||
update mmt_staging2.FTWET_TRS_H1_INT a
|
||||
set column3=(select column6 from mmt_staging2.FTWET_TRS_H1_INT b
|
||||
where trim(a.column2)=trim(b.column5)
|
||||
and b.column5='Season')
|
||||
where a.column2='Season';
|
||||
|
||||
update mmt_staging2.FTWET_TRS_H1_INT a
|
||||
set column3=(select column6 from mmt_staging2.FTWET_TRS_H1_INT b
|
||||
where trim(a.column2)=trim(b.column5)
|
||||
and b.column5='Type of Soil')
|
||||
where a.column2='Type of Soil';
|
||||
|
||||
|
||||
update mmt_staging2.FTWET_TRS_H1_INT a
|
||||
set column3=(select column6 from mmt_staging2.FTWET_TRS_H1_INT b
|
||||
where trim(a.column2)=trim(b.column5)
|
||||
and b.column5='Soil Cone Index (kPa)')
|
||||
where a.column2='Soil Cone Index (kPa)';
|
||||
|
||||
|
||||
update mmt_staging2.FTWET_TRS_H1_INT a
|
||||
set column3=(select column6 from mmt_staging2.FTWET_TRS_H1_INT b
|
||||
where trim(a.column2)=trim(b.column5)
|
||||
and b.column5='Field Condition')
|
||||
where a.column2='Field Condition';
|
||||
|
||||
insert into mmt_staging2.FTWET_TRS_H1_Block
|
||||
(
|
||||
dummy_f,
|
||||
Report_Reference_No,
|
||||
Objective_Of_Test,
|
||||
Background_of_Test,
|
||||
Job_Order_No,
|
||||
Test_Location,
|
||||
Soil_Moisture_Content_,
|
||||
Soil_Bulk_Density_g_cc,
|
||||
Test_Engineer,
|
||||
Test_Operator,
|
||||
Date_of_Test,
|
||||
Report_Date,
|
||||
Season,
|
||||
Type_of_Soil,
|
||||
Soil_Cone_Index_kPa,
|
||||
Field_Condition
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text]) AS val
|
||||
FROM mmt_staging2.FTWET_TRS_H1_INT
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text,
|
||||
a_11 text,a_12 text,a_13 text,a_14 text,a_15 text);
|
||||
|
||||
|
||||
|
||||
delete from mmt_staging2.FTWET_TRS_H1_Block where dummy_f is null ;
|
||||
execute 'update mmt_staging2.FTWET_TRS_H1_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
insert into mmt_staging2.FTWET_TRS_SPEC_Block
|
||||
(
|
||||
dummy_f,
|
||||
Tractor_Model,
|
||||
Tractor_Make,
|
||||
Tractor_Sr_No,
|
||||
Tractor_Engine_HP,
|
||||
FIP_Type,
|
||||
hour_Meter_Reading,
|
||||
Steering_Type,
|
||||
Transmission_Type,
|
||||
Wheel_Drive_Type_WD,
|
||||
EGR_Yes_No,
|
||||
Brake_Type,
|
||||
PTO_Type,
|
||||
Standard_PTO_Speed_RPM,
|
||||
EPTO_Speed_RPM,
|
||||
Front_Tyre_Make,
|
||||
Front_Tyre_Size,
|
||||
Front_Tyre_Pressure_psi,
|
||||
Rear_Tyre_Make,
|
||||
Rear_Tyre_Size,
|
||||
Rear_Tyre_Pressure_psi ,
|
||||
Tractor_Weight_kg_Front ,
|
||||
Tractor_Weight_kg_Rear ,
|
||||
Tractor_Weight_kg_Total,
|
||||
Ballasted_Tractor_Accessories,
|
||||
Mechanical_Ballast_Rear_in_KG ,
|
||||
Water_Ballast_Rear,
|
||||
Mechanical_Ballast_Front,
|
||||
Mechanical_Ballast_Front_in_Kg,
|
||||
Total_Ballast_Weight
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text]) AS val
|
||||
FROM mmt_staging2.stg_process_table_ftwet_trs where rank_tag=''FTWET_TRS_SPEC''
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,
|
||||
a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text,a_21 text,
|
||||
a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text);
|
||||
|
||||
|
||||
|
||||
delete from mmt_staging2.FTWET_TRS_SPEC_Block where dummy_f is null ;
|
||||
execute 'update mmt_staging2.FTWET_TRS_SPEC_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
insert into mmt_staging2.FTWET_TRS_Engine_RPM_Block
|
||||
(
|
||||
dummy_f,
|
||||
Tractor_model,
|
||||
Tractor_make,
|
||||
Low_Idle,
|
||||
High_Idle,
|
||||
Rated_RPM,
|
||||
Engine_to_PTO_Ratio_540_PTO,
|
||||
Engine_to_PTO_Ratio_540E_PTO
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text]) AS val
|
||||
FROM mmt_staging2.stg_process_table_ftwet_trs where rank_tag=''FTWET_TRS_Engine_RPM''
|
||||
or (rank_tag=''FTWET_TRS_SPEC'' and rank in (1,2))
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text);
|
||||
|
||||
|
||||
|
||||
delete from mmt_staging2.FTWET_TRS_Engine_RPM_Block where dummy_f is null ;
|
||||
execute 'update mmt_staging2.FTWET_TRS_Engine_RPM_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
insert into mmt_staging2.FTWET_TRS_Implement_Block
|
||||
(
|
||||
dummy_f,
|
||||
Name_of_Implement,
|
||||
Type_of_Implement,
|
||||
Make_of_Implement,
|
||||
No_of_bottoms_Tyne_Disc_Blade,
|
||||
Cutting_Width_m,
|
||||
Implement_Weight_Kg,
|
||||
Hitch_Category,
|
||||
Span_cm_For_Mounted_Implement,
|
||||
Mast_Height_cm_For_Mounted_Implement,
|
||||
Type_of_Cage_Wheel_Half_Cage_wheel_Full_Cage_Wheel,
|
||||
Cage_Wheel_Width_mm,
|
||||
Cage_wheel_Weight,
|
||||
Cage_Wheel_inner_Outer_Ring_Dia_mm,
|
||||
Cage_Wheel_Center_Ring_Dia_mm,
|
||||
Distance_between_RHS_LHS_cage_wheel_Inner_Ring_mm_For_Full_Cage_wheel,
|
||||
No_of_angles_on_cage_wheel,
|
||||
No_of_days_of_water_logging,
|
||||
Depth_of_water_mm ,
|
||||
FDPD_TDC_Mar15_008
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3,column4,column5,column6}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text]) AS val
|
||||
FROM mmt_staging2.stg_process_table_ftwet_trs where rank_tag=''FTWET_TRS_Implement''
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t ( col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text
|
||||
,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text);
|
||||
|
||||
|
||||
delete from mmt_staging2.FTWET_TRS_Implement_Block where dummy_f is null ;
|
||||
execute 'update mmt_staging2.FTWET_TRS_Implement_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_format='''||p_file_format||''',
|
||||
sheet_mnemonic='''||p_sheet_mnemonic||'''';
|
||||
|
||||
end
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
select mmt_staging2.fn_FTWET_TRS_Block
|
||||
(20,1,'FTWET','FTWET_TRS',181);
|
||||
/*FTWET_TRS ends*/
|
||||
|
||||
Reference in New Issue
Block a user