387 lines
11 KiB
Plaintext
387 lines
11 KiB
Plaintext
|
|
select * from union_tractor_spec order by src_table_name,syspk;
|
|
|
|
|
|
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)
|
|
);
|
|
|
|
|
|
create index i_mmt_format_config_format_F1_modified_run_date
|
|
on mmt_format_config(format,F1_modified,run_date);
|
|
|
|
|
|
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='dry_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='dry_field_spec';
|
|
|
|
update mmt_format_config set row_previous_number=row_number_start-1;
|
|
|
|
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 dry_field_spec_test_instance_1;
|
|
|
|
create table dry_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 src_table_name='plough'
|
|
order by a.syspk;
|
|
|
|
select * from dry_field_spec_test_instance_1;
|
|
|
|
drop table if exists dry_field_spec_test_specific_2;
|
|
|
|
create table dry_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 src_table_name='plough'
|
|
order by a.syspk;
|
|
|
|
|
|
drop table if exists dry_field_spec_engine_rpm_3;
|
|
|
|
create table dry_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 src_table_name='plough'
|
|
order by a.syspk;
|
|
|
|
drop table if exists dry_field_spec_implement_4;
|
|
|
|
create table dry_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 src_table_name='plough'
|
|
order by a.syspk;
|
|
|
|
|
|
|
|
insert into dry_field_spec_test_instance_1(column2) values ('Date of Test');
|
|
|
|
insert into dry_field_spec_test_instance_1(column2) values ('Report Date');
|
|
|
|
insert into dry_field_spec_test_instance_1(column2) values ('Season');
|
|
|
|
insert into dry_field_spec_test_instance_1(column2) values ('Type of Soil');
|
|
|
|
insert into dry_field_spec_test_instance_1(column2) values ('Soil Cone Index (kPa)');
|
|
|
|
insert into dry_field_spec_test_instance_1(column2) values ('Field Condition');
|
|
|
|
select * from dry_field_spec_test_instance_1;
|
|
|
|
alter table dry_field_spec_test_instance_1 add column transpose_syspk serial primary key;
|
|
|
|
update dry_field_spec_test_instance_1 a
|
|
set column3=(select column5 from dry_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 dry_field_spec_test_instance_1 a
|
|
set column3=(select column7 from dry_field_spec_test_instance_1 b
|
|
where trim(a.column2)=trim(b.column5)
|
|
and b.column5='Report Date')
|
|
where a.column2='Report Date';
|
|
|
|
update dry_field_spec_test_instance_1 a
|
|
set column3=(select column6 from dry_field_spec_test_instance_1 b
|
|
where trim(a.column2)=trim(b.column5)
|
|
and b.column5='Season')
|
|
where a.column2='Season';
|
|
|
|
update dry_field_spec_test_instance_1 a
|
|
set column3=(select column6 from dry_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 dry_field_spec_test_instance_1 a
|
|
set column3=(select column6 from dry_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 dry_field_spec_test_instance_1 a
|
|
set column3=(select column6 from dry_field_spec_test_instance_1 b
|
|
where trim(a.column2)=trim(b.column4)
|
|
and b.column4='Field Condition')
|
|
where a.column2='Field Condition';
|
|
|
|
alter table dry_field_spec_test_instance_1 add column a_c text;
|
|
|
|
alter table dry_field_spec_test_instance_1 add column transpose_syspk serial primary key;
|
|
|
|
update dry_field_spec_test_instance_1 set a_c=concat('a_',transpose_syspk);
|
|
|
|
|
|
create table transpose_dry_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_dry_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,src_table_name,column1,column2,column3,column4,column5,column6,column7,column8,is_rownumber_fetched}''::text[]) AS col
|
|
, row_number() OVER ()
|
|
, unnest(ARRAY[syspk::text,src_table_name::text,column1::text,column2::text,column3::text,column4::text,column5::text,column6::text,column7::text,column8::text,is_rownumber_fetched::text]) AS val
|
|
FROM dry_field_spec_test_instance_1
|
|
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)
|
|
|
|
alter table dry_field_spec_test_specific_2 drop column if exists a_c ;
|
|
|
|
alter table dry_field_spec_test_specific_2 add column a_c text;
|
|
|
|
alter table dry_field_spec_test_specific_2 add column transpose_syspk serial primary key;
|
|
|
|
update dry_field_spec_test_specific_2 set a_c=concat('a_',transpose_syspk);
|
|
|
|
drop table transpose_dry_field_spec_test_specific_2;
|
|
|
|
create table transpose_dry_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,
|
|
Rear_Tyre_Make text,
|
|
Rear_Tyre_Size text,
|
|
Rront_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_KG text,
|
|
Water_Ballast_Rear text,
|
|
Mechanical_Ballast_Front text,
|
|
Total_Ballast_Weight text
|
|
);
|
|
|
|
insert into transpose_dry_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,
|
|
Rear_Tyre_Make,
|
|
Rear_Tyre_Size,
|
|
Rront_Tyre_Pressure_psi,
|
|
Tractor_Weight_kg_Front,
|
|
Tractor_Weight_kg_Rear,
|
|
Tractor_Weight_kg_Total,
|
|
Ballasted_Tractor_Accessories,
|
|
Mechanical_Ballast_Rear_KG,
|
|
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 dry_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 dry_field_spec_engine_rpm_3 add column a_c text;
|
|
|
|
alter table dry_field_spec_engine_rpm_3 add column transpose_syspk serial primary key;
|
|
|
|
update dry_field_spec_engine_rpm_3 set a_c=concat('a_',transpose_syspk);
|
|
|
|
|
|
create table tranpose_dry_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 tranpose_dry_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 dry_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_45 text);
|
|
|
|
|
|
alter table dry_field_spec_implement_4 add column a_c text;
|
|
|
|
alter table dry_field_spec_implement_4 add column transpose_syspk serial primary key;
|
|
|
|
update dry_field_spec_implement_4 set a_c=concat('a_',transpose_syspk);
|
|
|
|
|
|
drop table transpose_dry_field_spec_implement_4;
|
|
|
|
create table transpose_dry_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,
|
|
Hitch_Category text,
|
|
Span_cm_For_Mounted_Implement text,
|
|
Mast_Height_cm_For_Mounted_Implement text,
|
|
FDPD_TDC_Mar15_008 text
|
|
);
|
|
|
|
|
|
insert into transpose_dry_field_spec_implement_4
|
|
(
|
|
dummy,
|
|
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(''{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 dry_field_spec_implement_4
|
|
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);
|
|
;
|
|
|
|
|