first commit
This commit is contained in:
381
MMT SQL/mmt_rotovator_spec.txt
Normal file
381
MMT SQL/mmt_rotovator_spec.txt
Normal file
@@ -0,0 +1,381 @@
|
||||
drop table if exists mmt_format_config;
|
||||
|
||||
create table mmt_format_config
|
||||
(
|
||||
syspk serial primary key,
|
||||
format varchar,
|
||||
F1_source varchar(100),
|
||||
F1_modified varchar(100),
|
||||
row_number_start int,
|
||||
row_previous_number int,
|
||||
row_read_end int,
|
||||
run_date date not null default CURRENT_DATE,
|
||||
run_sheet_name varchar(100),
|
||||
run_file_time timestamp,
|
||||
run_file_name varchar(250)
|
||||
);
|
||||
|
||||
insert into mmt_format_config(f1_modified)
|
||||
values
|
||||
('Tractor Specifications Sheet'),
|
||||
('Tractor Specifications'),
|
||||
('Engine RPM Data:'),
|
||||
('Implement Details');
|
||||
|
||||
update mmt_format_config set f1_source=f1_modified;
|
||||
|
||||
update mmt_format_config set f1_source=trim(trailing from f1_source);
|
||||
|
||||
update mmt_format_config set f1_source=trim(leading from f1_source);
|
||||
|
||||
update mmt_format_config set format='wet_field_spec' where format is null;
|
||||
|
||||
select * from mmt_format_config;
|
||||
|
||||
update mmt_format_config a
|
||||
set row_number_start=(select min(b.syspk)
|
||||
from union_tractor_spec b
|
||||
where f1_source=column2
|
||||
and b.is_rownumber_fetched is null)
|
||||
where a.row_number_start is null and format='wet_field_spec';
|
||||
|
||||
update mmt_format_config set row_previous_number=row_number_start-1 where row_previous_number is null;
|
||||
|
||||
update mmt_format_config a
|
||||
set row_read_end= (select b.row_number_start
|
||||
from mmt_format_config b
|
||||
where b.syspk=a.syspk+1 );
|
||||
|
||||
drop table if exists wet_field_spec_test_instance_1;
|
||||
|
||||
create table wet_field_spec_test_instance_1 as
|
||||
select a.* from union_tractor_spec a
|
||||
join mmt_format_config b
|
||||
on a.syspk>row_number_start
|
||||
and (a.syspk< row_read_end or row_read_end is null)
|
||||
and f1_modified='Tractor Specifications Sheet' and a.src_table_name ='rotavator' and b.format ='wet_field_spec'
|
||||
order by a.syspk;
|
||||
|
||||
select * from wet_field_spec_test_instance_1;
|
||||
|
||||
drop table if exists wet_field_spec_test_specific_2;
|
||||
|
||||
create table wet_field_spec_test_specific_2 as
|
||||
select a.* from union_tractor_spec a
|
||||
join mmt_format_config b
|
||||
on a.syspk>row_number_start
|
||||
and (a.syspk< row_read_end or row_read_end is null)
|
||||
and f1_modified='Tractor Specifications' and a.src_table_name ='rotavator' and b.format ='wet_field_spec'
|
||||
order by a.syspk;
|
||||
|
||||
alter table wet_field_spec_test_specific_2 add column transpose_syspk serial primary key;
|
||||
|
||||
select * from wet_field_spec_test_specific_2 ;
|
||||
------------------------------------------------------------------------------------------
|
||||
drop table if exists wet_field_spec_engine_rpm_3;
|
||||
|
||||
create table wet_field_spec_engine_rpm_3 as
|
||||
select a.* from union_tractor_spec a
|
||||
join mmt_format_config b
|
||||
on a.syspk>row_number_start
|
||||
and (a.syspk< row_read_end or row_read_end is null)
|
||||
and f1_modified='Engine RPM Data:' and a.src_table_name ='rotavator' and b.format ='wet_field_spec'
|
||||
order by a.syspk;
|
||||
|
||||
alter table wet_field_spec_engine_rpm_3 add column transpose_syspk serial primary key;
|
||||
|
||||
----------------------------------------------------------
|
||||
drop table if exists wet_field_spec_implement_4;
|
||||
|
||||
create table wet_field_spec_implement_4 as
|
||||
select a.* from union_tractor_spec a
|
||||
join mmt_format_config b
|
||||
on a.syspk>row_number_start
|
||||
and (a.syspk< row_read_end or row_read_end is null)
|
||||
and f1_modified='Implement Details' and a.src_table_name ='rotavator' and b.format ='wet_field_spec'
|
||||
order by a.syspk;
|
||||
|
||||
alter table wet_field_spec_implement_4 add column transpose_syspk serial primary key;
|
||||
|
||||
----------------------------------------
|
||||
insert into wet_field_spec_test_instance_1(column2) values ('Date of Test');
|
||||
|
||||
insert into wet_field_spec_test_instance_1(column2) values ('Report Date');
|
||||
|
||||
insert into wet_field_spec_test_instance_1(column2) values ('Season');
|
||||
|
||||
insert into wet_field_spec_test_instance_1(column2) values ('Type of Soil');
|
||||
|
||||
insert into wet_field_spec_test_instance_1(column2) values ('Soil Cone Index (kPa)');
|
||||
|
||||
insert into wet_field_spec_test_instance_1(column2) values ('Field Condition');
|
||||
|
||||
alter table wet_field_spec_test_instance_1 add column transpose_syspk serial primary key;
|
||||
|
||||
update wet_field_spec_test_instance_1 a
|
||||
set column3=(select column5 from wet_field_spec_test_instance_1 b
|
||||
where trim(a.column2)=trim(b.column4)
|
||||
and b.column4='Date of Test')
|
||||
where a.column2='Date of Test' ;
|
||||
|
||||
update wet_field_spec_test_instance_1 a
|
||||
set column3=(select column7 from wet_field_spec_test_instance_1 b
|
||||
where trim(a.column2)=trim(b.column6)
|
||||
and b.column6='Report Date')
|
||||
where a.column2='Report Date';
|
||||
|
||||
update wet_field_spec_test_instance_1 a
|
||||
set column3=(select column6 from wet_field_spec_test_instance_1 b
|
||||
where trim(a.column2)=trim(b.column5)
|
||||
and b.column5='Season')
|
||||
where a.column2='Season';
|
||||
|
||||
update wet_field_spec_test_instance_1 a
|
||||
set column3=(select column6 from wet_field_spec_test_instance_1 b
|
||||
where trim(a.column2)=trim(b.column5)
|
||||
and b.column5='Type of Soil')
|
||||
where a.column2='Type of Soil';
|
||||
|
||||
|
||||
update wet_field_spec_test_instance_1 a
|
||||
set column3=(select column6 from wet_field_spec_test_instance_1 b
|
||||
where trim(a.column2)=trim(b.column5)
|
||||
and b.column5='Soil Cone Index (kPa)')
|
||||
where a.column2='Soil Cone Index (kPa)';
|
||||
|
||||
|
||||
update wet_field_spec_test_instance_1 a
|
||||
set column3=(select column6 from wet_field_spec_test_instance_1 b
|
||||
where trim(a.column2)=trim(b.column5)
|
||||
and b.column5='Field Condition')
|
||||
where a.column2='Field Condition';
|
||||
|
||||
alter table wet_field_spec_test_instance_1 add column a_c text;
|
||||
|
||||
update wet_field_spec_test_instance_1 set a_c=concat('a_',transpose_syspk);
|
||||
|
||||
create table transpose_wet_field_spec_test_instance_1
|
||||
(
|
||||
dummy text,
|
||||
Report_Reference_No text,
|
||||
Objective_Of_Test text,
|
||||
Background_of_Test text,
|
||||
Job_Order_No text,
|
||||
Test_Location text,
|
||||
Soil_Moisture_Content_ text,
|
||||
Soil_Bulk_Density_g_cc text,
|
||||
Test_Engineer text,
|
||||
Test_Operator text,
|
||||
Date_of_Test text,
|
||||
Report_Date text,
|
||||
Season text,
|
||||
Type_of_Soil text,
|
||||
Soil_Cone_Index_kPa text,
|
||||
Field_Condition text
|
||||
);
|
||||
|
||||
insert into transpose_wet_field_spec_test_instance_1
|
||||
(
|
||||
dummy,
|
||||
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(''{syspk,column2,column3,column4,column5,column6,column7,column8,is_rownumber_fetched}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[syspk::text,column1::text,column2::text,column3::text,column4::text,column5::text,column6::text,column7::text,column8::text,is_rownumber_fetched::text]) AS val
|
||||
FROM wet_field_spec_test_instance_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);
|
||||
|
||||
alter table wet_field_spec_test_specific_2 add column a_c text;
|
||||
|
||||
update wet_field_spec_test_specific_2 set a_c=concat('a_',transpose_syspk);
|
||||
|
||||
create table transpose_wet_field_spec_test_specific_2
|
||||
(
|
||||
dummy text,
|
||||
Tractor_Model text,
|
||||
Tractor_Make text,
|
||||
Tractor_Sr_No text,
|
||||
Tractor_Engine_HP text,
|
||||
FIP_Type text,
|
||||
Hour_Meter_Reading text,
|
||||
Steering_Type text,
|
||||
Transmission_Type text,
|
||||
Wheel_Drive_Type_WD text,
|
||||
EGR_Yes_No text,
|
||||
Brake_Type text,
|
||||
PTO_Type text,
|
||||
Standard_PTO_Speed_RPM text,
|
||||
EPTO_Speed_RPM text,
|
||||
Front_Tyre_Make text,
|
||||
Front_Tyre_Size text,
|
||||
Front_Tyre_Pressure_psi text,
|
||||
RearTyre_Make text,
|
||||
Rear_Tyre_Size text,
|
||||
Rear_Tyre_Pressure_psi text,
|
||||
Tractor_Weight_kg_Front text,
|
||||
Tractor_Weight_kg_Rear text,
|
||||
Tractor_Weight_kg_Total text,
|
||||
Ballasted_Tractor_Accessories text,
|
||||
Mechanical_Ballast_Rear text,
|
||||
Water_Ballast_Rear text,
|
||||
Mechanical_Ballast_Front text,
|
||||
Total_Ballast_Weight text
|
||||
);
|
||||
|
||||
insert into transpose_wet_field_spec_test_specific_2
|
||||
(
|
||||
dummy,
|
||||
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,
|
||||
RearTyre_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,
|
||||
Water_Ballast_Rear,
|
||||
Mechanical_Ballast_Front,
|
||||
Total_Ballast_Weight
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{syspk,src_table_name,column2,column3,column4,column5,column6,column7,column8,is_rownumber_fetched}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[syspk::text,src_table_name::text,column2::text,column3::text,column4::text,column5::text,column6::text,column7::text,column8::text,is_rownumber_fetched::text]) AS val
|
||||
FROM wet_field_spec_test_specific_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);
|
||||
|
||||
|
||||
alter table wet_field_spec_engine_rpm_3 add column a_c text;
|
||||
|
||||
update wet_field_spec_engine_rpm_3 set a_c=concat('a_',transpose_syspk);
|
||||
|
||||
create table transpose_wet_field_spec_engine_rpm_3
|
||||
(
|
||||
dummy text,
|
||||
Low_Idle text,
|
||||
High_Idle text,
|
||||
Rated_RPM text,
|
||||
Engine_to_PTO_Ratio_540_PTO text,
|
||||
Engine_to_PTO_Ratio_540E_PTO text
|
||||
);
|
||||
|
||||
|
||||
insert into transpose_wet_field_spec_engine_rpm_3
|
||||
(
|
||||
dummy,
|
||||
Low_Idle,
|
||||
High_Idle,
|
||||
Rated_RPM,
|
||||
Engine_to_PTO_Ratio_540_PTO,
|
||||
Engine_to_PTO_Ratio_540E_PTO
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{syspk,src_table_name,column2,column3,column4,column5,column6,column7,column8,is_rownumber_fetched}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[syspk::text,src_table_name::text,column2::text,column3::text,column4::text,column5::text,column6::text,column7::text,column8::text,is_rownumber_fetched::text]) AS val
|
||||
FROM wet_field_spec_engine_rpm_3
|
||||
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);
|
||||
|
||||
alter table wet_field_spec_implement_4 add column a_c text;
|
||||
|
||||
update wet_field_spec_implement_4 set a_c=concat('a_',transpose_syspk);
|
||||
|
||||
create table transpose_wet_field_spec_implement_4
|
||||
(
|
||||
dummy text,
|
||||
Name_of_Implement text,
|
||||
Type_of_Implement text,
|
||||
Make_of_Implement text,
|
||||
No_of_bottoms_Tyne_Disc_Blade text,
|
||||
Cutting_Width_m text,
|
||||
Implement_Weight_Kg text,
|
||||
Span_cm_For_Mounted_Implement text,
|
||||
Hitch_Category text,
|
||||
Mast_Height_cm_For_Mounted_Implement text,
|
||||
Type_of_Cage_Wheel_Half_Cage_wheel_Full_Cage_Wheel text,
|
||||
Cage_Wheel_Width_mm text,
|
||||
Cage_wheel_Weight text,
|
||||
Cage_Wheel_inner_Outer_Ring_Dia_mm text,
|
||||
Cage_Wheel_Center_Ring_Dia_mm text,
|
||||
Distance_between_RHS_LHS_cage_wheel_Inner_Ring_mm_For_Full_Cage_wheel text,
|
||||
No_of_angles_on_cage_wheel text,
|
||||
No_of_days_of_water_logging text,
|
||||
Depth_of_water_mm text,
|
||||
FDPD_TDC_Mar15_008 text
|
||||
);
|
||||
insert into transpose_wet_field_spec_implement_4
|
||||
(
|
||||
Name_of_Implement,
|
||||
Type_of_Implement,
|
||||
Make_of_Implement,
|
||||
No_of_bottoms_Tyne_Disc_Blade,
|
||||
Cutting_Width_m,
|
||||
Implement_Weight_Kg,
|
||||
Span_cm_For_Mounted_Implement,
|
||||
Hitch_Category,
|
||||
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(''{syspk,src_table_name,column2,column3,column4,column5,column6,column7,column8,is_rownumber_fetched}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[syspk::text,src_table_name::text,column2::text,column3::text,column4::text,column5::text,column6::text,column7::text,column8::text,is_rownumber_fetched::text]) AS val
|
||||
FROM wet_field_spec_implement_4
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t (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);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user