Changes between Version 13 and Version 14 of Meuse dbeel


Ignore:
Timestamp:
Jun 16, 2014 1:02:10 PM (11 years ago)
Author:
laura
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Meuse dbeel

    v13 v14  
    631631 
    632632}}} 
     633 
     634{{{#!sql 
     635 
     636Intégration des données de la dernière version de la BD_MAP dan dbeel: 
     637 
     638 
     639-- dump de bd_map sch public vers EDA2 public: 
     640pg_dump -h 1.100.1.6 -U postgres bd_map| psql -h 1.100.1.6 -U postgres eda2 
     641-- transfers de public à ONEMA. Les tables existent déjà. 
     642ALTER TABLE zonepeche SET SCHEMA onema; 
     643ALTER TABLE version SET SCHEMA onema; 
     644ALTER TABLE taxon SET SCHEMA onema; 
     645ALTER TABLE tableauclassetaille SET SCHEMA onema; 
     646ALTER TABLE station SET SCHEMA onema; 
     647ALTER TABLE patho SET SCHEMA onema; 
     648ALTER TABLE passtaxon SET SCHEMA onema; 
     649ALTER TABLE optaxon SET SCHEMA onema; 
     650ALTER TABLE operation SET SCHEMA onema; 
     651ALTER TABLE mensurationindiv SET SCHEMA onema; 
     652ALTER TABLE codier SET SCHEMA onema; 
     653ALTER TABLE classe_taille_taxon SET SCHEMA onema; 
     654ALTER TABLE lotpeche SET SCHEMA onema; 
     655 
     656INSERT INTO  dbeel.establishment (et_establishment_name) VALUES ('ONEMA'); 
     657INSERT INTO dbeel.data_provider(dp_name, dp_et_id) VALUES ('Laurent Beaulaton',1); 
     658 
     659 
     660-- Bon il est pas content ca il n y a pas de colonnes the_geom 
     661select st_abcisse, st_ordonnee from onema.station; 
     662ALTER TABLE onema.station ADD COLUMN the_geom geometry; 
     663UPDATE onema.station SET the_geom = ST_GeometryFromText ('POINT(' || st_abcisse|| ' ' ||  st_ordonnee || ')', 
     66427572) 
     665select * from onema.station 
     666-- il faut trouver quelle colonne il prend pour the_geom 
     667 
     668 
     669DROP TABLE if exists onema.station_onema CASCADE; 
     670CREATE TABLE onema.station_onema ( 
     671        LIKE onema.station, 
     672        CONSTRAINT pk_so_op_id PRIMARY KEY (op_id), 
     673        CONSTRAINT fk_so_observation_place_type_id FOREIGN KEY (op_no_observationplacetype)  
     674                REFERENCES dbeel_nomenclature.observation_place_type (no_id)  
     675                MATCH SIMPLE ON UPDATE CASCADE ON DELETE RESTRICT 
     676) INHERITS (dbeel.observation_places); 
     677-- select * from onema.station_onema, the_geom c'ets la 8ième colonne 
     678-- select * from onema.station --> il faut placer the_geom au même niveau 
     679 
     680INSERT INTO onema.station_onema 
     681        SELECT  uuid_generate_v4() AS op_id, 
     682        'onema' AS op_gis_systemname , 
     683        'BDMAP' AS op_gis_layername,  
     684        s.st_id AS op_gislocation, 
     685        s.st_localisation AS op_placename, 
     686        10 AS op_no_observationplacetype, -- Sampling station 
     687        NULL AS  op_op_id, 
     688        s.the_geom AS the_geom,  
     689  s.st_id, 
     690  s.st_altitude, 
     691  s.st_abcisse, 
     692  s.st_codecsp, 
     693  s.st_codesie, 
     694  s.st_datearret, 
     695  s.st_datecreation, 
     696  s.st_distancesource, 
     697  s.st_distancemer, 
     698  s.st_finalite, 
     699  s.st_imageign, 
     700  s.st_imagedept, 
     701  s.st_lieudit, 
     702  s.st_limites, 
     703  s.st_localisation, 
     704  s.st_longueur, 
     705  s.st_moduleia, 
     706  s.st_cd_naturecourseau, 
     707  s.st_ordonnee, 
     708  s.st_penteign, 
     709  s.st_pkaval, 
     710  s.st_raisremp, 
     711  s.st_sbv, 
     712  s.st_t_janvier, 
     713  s.st_t_juillet, 
     714  s.st_cd_typecourseau, 
     715  s.st_cd_tet, 
     716  s.st_st_id, 
     717  s.st_cm_id, 
     718  s.st_cx_id, 
     719  s.st_th_id, 
     720  s.st_eh_id, 
     721  s.st_uh_id, 
     722  s.st_dt_cre, 
     723  s.st_dt_maj, 
     724  s.st_qi_maj, 
     725  s.st_masseeau, 
     726  s.st_abcisse_l93, 
     727  s.st_ordonnee_l93 FROM onema.station s ; 
     728 
     729DROP TABLE if exists onema.operation_onema CASCADE; 
     730CREATE TABLE onema.operation_onema ( 
     731        LIKE onema.operation, 
     732        CONSTRAINT pk_oo_ob_id PRIMARY KEY (ob_id), 
     733        CONSTRAINT fk_oo_ob_op_id FOREIGN KEY (ob_op_id)         
     734                REFERENCES onema.station_onema (op_id) MATCH SIMPLE 
     735                ON UPDATE CASCADE ON DELETE RESTRICT,    
     736        CONSTRAINT fk_oo_dp_id FOREIGN KEY (ob_dp_id)    
     737                REFERENCES dbeel.data_provider (dp_id) MATCH SIMPLE 
     738                ON UPDATE CASCADE ON DELETE RESTRICT, 
     739        CONSTRAINT fk_oo_electrofishing_mean FOREIGN KEY (ef_no_electrofishing_mean) 
     740                REFERENCES dbeel_nomenclature.electrofishing_mean (no_id) MATCH SIMPLE 
     741                ON UPDATE CASCADE ON DELETE RESTRICT, 
     742        CONSTRAINT fk_oo_electrofishing_method FOREIGN KEY (ef_no_fishingmethod) 
     743                REFERENCES dbeel_nomenclature.scientific_observation_method (no_id) MATCH SIMPLE 
     744                ON UPDATE CASCADE ON DELETE RESTRICT, 
     745        CONSTRAINT fk_oo_ob_no_origin FOREIGN KEY (ob_no_origin) 
     746                REFERENCES dbeel_nomenclature.observation_origin (no_id) MATCH SIMPLE 
     747                ON UPDATE CASCADE ON DELETE RESTRICT, 
     748        CONSTRAINT fk_oo_ob_no_period FOREIGN KEY (ob_no_period) 
     749                REFERENCES dbeel_nomenclature.period_type (no_id) MATCH SIMPLE 
     750                ON UPDATE CASCADE ON DELETE RESTRICT, 
     751        CONSTRAINT fk_oo_ob_no_type FOREIGN KEY (ob_no_type) 
     752                REFERENCES dbeel_nomenclature.observation_type (no_id) MATCH SIMPLE 
     753                ON UPDATE CASCADE ON DELETE RESTRICT 
     754) INHERITS (dbeel.electrofishing); 
     755 
     756-- select * from onema.station 
     757 
     758 
     759INSERT INTO onema.operation_onema 
     760        SELECT  
     761        uuid_generate_v4() AS ob_id , 
     762        observation_origin.no_id AS ob_no_origin, 
     763        observation_type.no_id AS ob_no_type,  
     764        period_type.no_id AS ob_no_period, 
     765        op_datedebut AS ob_starting_date, 
     766        op_datedebut AS ob_ending_date, 
     767        station.op_id AS ob_op_id,  
     768        data_provider.dp_id AS ob_dp_id, -- ONEMA 
     769        61 AS ef_no_fishingmethod, -- TODO update this correctly here it is electrofishing unknown 
     770        electrofishing_mean.no_id AS ef_no_electrofishing_mean,  
     771        case when operation.op_surfaceechantillon >0 then operation.op_surfaceechantillon 
     772                else NULL 
     773                end AS ef_wetted_area,  
     774        case when operation.op_longueur>0  then operation.op_longueur 
     775                else NULL 
     776                end AS ef_fished_length, 
     777        case when operation.op_cs_largeurlameeau>0 then operation.op_cs_largeurlameeau 
     778                else null 
     779                end AS ef_fished_width, 
     780        operation.op_tempspeche AS ef_duration, 
     781        operation.op_nbrpassage AS ef_nbpas,  
     782        operation.*  
     783        FROM    dbeel_nomenclature.observation_origin, 
     784                dbeel_nomenclature.scientific_observation_method, 
     785                dbeel_nomenclature.observation_type, 
     786                dbeel_nomenclature.period_type,  
     787                dbeel.data_provider, 
     788                onema.station_onema AS station join onema.operation AS operation on station.st_id = operation.op_st_id, 
     789                dbeel_nomenclature.electrofishing_mean 
     790        WHERE observation_origin.no_name='Raw data'  
     791        AND scientific_observation_method.no_id=61 
     792        AND observation_type.no_name='Electro-fishing'  
     793        AND electrofishing_mean.no_name='Unknown'  
     794        AND period_type.no_name='Daily'  
     795        AND data_provider.dp_name='Laurent Beaulaton'; 
     796 
     797--------------------------------------------------------------------------------------- 
     798-- optaxon 
     799 
     800DROP TABLE if exists onema.optaxon_onema CASCADE; 
     801CREATE TABLE onema.optaxon_onema ( 
     802        LIKE onema.optaxon, 
     803        CONSTRAINT pk_opo_id PRIMARY KEY (ba_id), 
     804        CONSTRAINT fk_opo_ba_no_species_id FOREIGN KEY (ba_no_species)  
     805                REFERENCES dbeel_nomenclature.species (no_id)  
     806                ON DELETE RESTRICT ON UPDATE CASCADE, 
     807        CONSTRAINT fk_opo_ba_no_stage_id FOREIGN KEY (ba_no_stage)  
     808                REFERENCES dbeel_nomenclature.stage (no_id)  
     809                ON DELETE RESTRICT ON UPDATE CASCADE,    
     810        CONSTRAINT fk_opo_ba_value_type FOREIGN KEY (ba_no_value_type) 
     811                REFERENCES dbeel_nomenclature.value_type (no_id) 
     812                ON DELETE RESTRICT ON UPDATE CASCADE,    
     813        CONSTRAINT fk_opo_ba_no_biological_characteristic_type  FOREIGN KEY (ba_no_biological_characteristic_type) 
     814                REFERENCES dbeel_nomenclature.biological_characteristic_type (no_id) 
     815                ON DELETE RESTRICT ON UPDATE CASCADE,                    
     816        CONSTRAINT fk_opo_ba_no_individual_status FOREIGN KEY (ba_no_individual_status) 
     817                REFERENCES dbeel_nomenclature.individual_status(no_id)  
     818                ON DELETE RESTRICT ON UPDATE CASCADE,    
     819        CONSTRAINT fk_opo_ba_ob_id FOREIGN KEY (ba_ob_id) 
     820                REFERENCES onema.operation_onema(ob_id) --setting the constraint to the uppermost level dbeel.observations(ob_id) does not work ! 
     821                ON DELETE RESTRICT ON UPDATE CASCADE, 
     822        CONSTRAINT fk_opo_ba_ba_id FOREIGN KEY (ba_ba_id) 
     823                REFERENCES dbeel.batch(ba_id) -- here I'm setting the constraint to the uppermost level 
     824                ON DELETE RESTRICT ON UPDATE CASCADE 
     825                ) INHERITS (dbeel.batch); 
     826-- TODO: insert trigger 
     827 
     828INSERT INTO onema.optaxon_onema 
     829        SELECT uuid_generate_v4() AS ba_id, 
     830        species.no_id AS ba_no_species, 
     831        stage.no_id AS ba_no_stage, 
     832        value_type.no_id AS ba_no_value_type, 
     833        biological_characteristic_type.no_id AS ba_no_biological_characteristic_type, 
     834        optaxon.ot_effectif AS ba_quantity, 
     835        individual_status.no_id AS ba_no_individual_status, 
     836        1 AS ba_batch_level, 
     837        operation_onema.ob_id AS ba_ob_id, 
     838        NULL AS ba_ba_id, 
     839        optaxon.*  
     840        FROM dbeel_nomenclature.species, 
     841        dbeel_nomenclature.stage, 
     842        dbeel_nomenclature.biological_characteristic_type, 
     843        dbeel_nomenclature.value_type, 
     844        dbeel_nomenclature.individual_status, 
     845        onema.operation_onema AS operation_onema, 
     846        onema.optaxon 
     847        WHERE species.no_name='Anguilla anguilla' 
     848         AND stage.no_name='Yellow & silver eel mixed' 
     849         AND biological_characteristic_type.no_name='Number' 
     850         AND value_type.no_name='Raw data or Individual data' 
     851         AND individual_status.no_name='Alive' 
     852         AND operation_onema.op_id = optaxon.ot_op_id 
     853         AND optaxon.ot_ta_id=2; --9781 lines 
     854 
     855UPDATE onema.optaxon_onema SET ba_quantity = 0 WHERE ba_quantity IS NULL; --0 lines 
     856 
     857--------------------------------------------------------------------------------------- 
     858 
     859DROP TABLE if exists onema.passtaxon_onema CASCADE; 
     860CREATE TABLE onema.passtaxon_onema ( 
     861        LIKE onema.passtaxon, 
     862        CONSTRAINT pk_pao_id PRIMARY KEY (ba_id), 
     863        CONSTRAINT fk_pao_ba_no_species_id FOREIGN KEY (ba_no_species)  
     864                REFERENCES dbeel_nomenclature.species (no_id) MATCH SIMPLE 
     865                ON DELETE RESTRICT ON UPDATE CASCADE, 
     866        CONSTRAINT fk_pao_ba_no_stage_id FOREIGN KEY (ba_no_stage)  
     867                REFERENCES dbeel_nomenclature.stage (no_id) MATCH SIMPLE 
     868                ON DELETE RESTRICT ON UPDATE CASCADE,    
     869        CONSTRAINT fk_pao_ba_value_type FOREIGN KEY (ba_no_value_type) 
     870                REFERENCES dbeel_nomenclature.value_type (no_id) 
     871                ON DELETE RESTRICT ON UPDATE CASCADE,    
     872        CONSTRAINT fk_pao_ba_no_biological_characteristic_type  FOREIGN KEY (ba_no_biological_characteristic_type) 
     873                REFERENCES dbeel_nomenclature.biological_characteristic_type (no_id) 
     874                ON DELETE RESTRICT ON UPDATE CASCADE,    
     875        CONSTRAINT fk_pao_ba_no_individual_status FOREIGN KEY (ba_no_individual_status) 
     876                REFERENCES dbeel_nomenclature.individual_status(no_id) MATCH SIMPLE 
     877                ON DELETE RESTRICT ON UPDATE CASCADE,    
     878        CONSTRAINT fk_pao_ba_ob_id FOREIGN KEY (ba_ob_id) 
     879                REFERENCES onema.operation_onema(ob_id) --setting the constraint to the uppermost level dbeel.observations(ob_id) does not work ! 
     880                ON DELETE RESTRICT ON UPDATE CASCADE 
     881--      CONSTRAINT fk_pao_ba_ba_id FOREIGN KEY (ba_ba_id) 
     882--              REFERENCES dbeel.batch(ba_id) -- here I'm setting the constraint to the uppermost level 
     883--              ON DELETE RESTRICT ON UPDATE CASCADE 
     884                 
     885) INHERITS (dbeel.batch); 
     886-- TODO: insert trigger 
     887 
     888INSERT INTO onema.passtaxon_onema 
     889        SELECT uuid_generate_v4() AS ba_id, 
     890        species.no_id AS ba_no_species, 
     891        stage.no_id AS ba_no_stage, 
     892        value_type.no_id AS ba_no_value_type, 
     893        biological_characteristic_type.no_id AS ba_no_biological_characteristic_type, 
     894        passtaxon.pa_effectif AS ba_quantity, 
     895        individual_status.no_id AS ba_no_individual_status, 
     896        2 AS ba_batch_level, 
     897        operation_onema.ob_id AS ba_ob_id, 
     898        NULL AS ba_ba_id, 
     899        passtaxon.*  
     900        FROM dbeel_nomenclature.species,  
     901        dbeel_nomenclature.stage,  
     902        dbeel_nomenclature.biological_characteristic_type, 
     903        dbeel_nomenclature.value_type, 
     904        dbeel_nomenclature.individual_status,  
     905        onema.operation_onema AS operation_onema,  
     906        onema.passtaxon 
     907        WHERE species.no_name='Anguilla anguilla'  
     908        AND stage.no_name='Yellow & silver eel mixed'  
     909        AND biological_characteristic_type.no_name='Number'  
     910        AND value_type.no_name='Raw data or Individual data' 
     911        AND individual_status.no_name='Alive'  
     912        AND operation_onema.op_id = passtaxon.pa_op_id; 
     913         
     914-- select * from onema.optaxon_onema 
     915-- UPDATE onema.passtaxon_onema SET quantity = 0 WHERE quantity ISNULL; 
     916 
     917UPDATE onema.passtaxon_onema pao SET ba_ba_id=opo.ba_id FROM onema.optaxon_onema opo WHERE opo.ba_ob_id = pao.ba_ob_id; 
     918-- select * from onema.passtaxon_onema limit 100; 
     919DELETE FROM onema.passtaxon_onema where pa_ta_id!=2;  
     920-- select * from onema.passtaxon_onema order by pa_dt_maj --15396 rows, il y a 2011, 2012, 2013 
     921 
     922/*-------------------------------------------------------------------------------------- 
     923                lotpeche 
     924--------------------------------------------------------------------------------------*/ 
     925DROP TABLE if exists onema.lotpeche_onema CASCADE; 
     926CREATE TABLE onema.lotpeche_onema ( 
     927        LIKE onema.lotpeche, 
     928        CONSTRAINT pk_lopeo_id PRIMARY KEY (ba_id), 
     929        CONSTRAINT fk_lopeo_ba_no_species_id FOREIGN KEY (ba_no_species)  
     930                REFERENCES dbeel_nomenclature.species (no_id) MATCH SIMPLE 
     931                ON DELETE RESTRICT ON UPDATE CASCADE, 
     932        CONSTRAINT fk_lopeo_ba_no_stage_id FOREIGN KEY (ba_no_stage)  
     933                REFERENCES dbeel_nomenclature.stage (no_id) MATCH SIMPLE 
     934                ON DELETE RESTRICT ON UPDATE CASCADE,    
     935        CONSTRAINT fk_lopeo_ba_value_type FOREIGN KEY (ba_no_value_type) 
     936                REFERENCES dbeel_nomenclature.value_type (no_id) 
     937                ON DELETE RESTRICT ON UPDATE CASCADE,    
     938        CONSTRAINT fk_lopeo_ba_no_biological_characteristic_type        FOREIGN KEY (ba_no_biological_characteristic_type) 
     939                REFERENCES dbeel_nomenclature.biological_characteristic_type (no_id) 
     940                ON DELETE RESTRICT ON UPDATE CASCADE,    
     941        CONSTRAINT fk_lopeo_ba_no_individual_status FOREIGN KEY (ba_no_individual_status) 
     942                REFERENCES dbeel_nomenclature.individual_status(no_id) MATCH SIMPLE 
     943                ON DELETE RESTRICT ON UPDATE CASCADE,    
     944        CONSTRAINT fk_lopeo_ba_ob_id FOREIGN KEY (ba_ob_id) 
     945                REFERENCES onema.operation_onema(ob_id) --setting the constraint to the uppermost level dbeel.observations(ob_id) does not work ! 
     946                ON DELETE RESTRICT ON UPDATE CASCADE 
     947--      CONSTRAINT fk_lopeo_ba_ba_id FOREIGN KEY (ba_ba_id) 
     948--              REFERENCES dbeel.batch(ba_id) -- Il ne peut pas y avoir de contraintes de clé étrangères dans la table 
     949--              ON DELETE RESTRICT ON UPDATE CASCADE 
     950) INHERITS (dbeel.batch); 
     951 
     952-- TODO: insert trigger 
     953-- this is way too long, I'm only inserting the eels 
     954SELECT * FROM   onema.operation_onema  join onema.lotpeche on operation_onema.op_id = lotpeche.lo_op_id limit 10; 
     955 
     956INSERT INTO onema.lotpeche_onema 
     957        SELECT uuid_generate_v4() AS ba_id, 
     958        species.no_id AS ba_no_species, 
     959        stage.no_id AS ba_no_stage, 
     960        value_type.no_id AS ba_no_value_type, 
     961        biological_characteristic_type.no_id AS ba_no_biological_characteristic_type, 
     962        lotpeche.lo_effectif AS ba_quantity, 
     963        individual_status.no_id AS ba_no_individual_status, 
     964        3 AS ba_batch_level, 
     965        operation_onema.ob_id AS ba_ob_id, 
     966        NULL AS ba_ba_id, 
     967        lotpeche.*  
     968        FROM dbeel_nomenclature.species,  
     969        dbeel_nomenclature.stage,  
     970        dbeel_nomenclature.biological_characteristic_type,  
     971        dbeel_nomenclature.value_type, 
     972        dbeel_nomenclature.individual_status,  
     973        onema.operation_onema  join onema.lotpeche on operation_onema.op_id = lotpeche.lo_op_id  
     974        WHERE species.no_name='Anguilla anguilla'  
     975        AND stage.no_name='Yellow & silver eel mixed'  
     976        AND biological_characteristic_type.no_name='Number'  
     977        AND value_type.no_name='Raw data or Individual data'  
     978        AND individual_status.no_name='Alive'  
     979        AND lo_ta_id=2; 
     980 
     981UPDATE onema.lotpeche_onema lopeo SET ba_ba_id = pao.ba_id  
     982        FROM onema.passtaxon_onema  pao  
     983        WHERE lopeo.ba_ob_id = pao.ba_ob_id  
     984        AND lopeo.lo_numeropassage = pao.pa_numero; 
     985 
     986-- select * from onema.lotpeche_onema limit 100; 
     987 
     988 
     989--------------------------------------------------------------------------------------- 
     990-- Biological characteristic for lotpeche 
     991--------------------------------------------------------------------------------------- 
     992 
     993-- Ici les résultats biologiques sont par lot du coup pour chacun d'eux on a Lt min, taille minimum, Lt max, le poid du lot, poid moyen individuel 
     994DROP TABLE if exists onema.lotpeche_biol_charac_onema CASCADE; 
     995CREATE TABLE onema.lotpeche_biol_charac_onema ( 
     996        CONSTRAINT lotpeche_biol_charac_onema_id PRIMARY KEY (bc_id), 
     997        CONSTRAINT fk_lopebiocho_bc_characteristic_type FOREIGN KEY (bc_no_characteristic_type) 
     998                REFERENCES dbeel_nomenclature.biological_characteristic_type (no_id) ON DELETE RESTRICT ON UPDATE CASCADE, 
     999        CONSTRAINT fk_lopebiocho_bc_value_type  FOREIGN KEY (bc_no_value_type) 
     1000                REFERENCES dbeel_nomenclature.value_type (no_id) ON DELETE RESTRICT ON UPDATE CASCADE, 
     1001        CONSTRAINT fk_lopebiocho_bc_ba_id FOREIGN KEY (bc_ba_id) 
     1002                REFERENCES onema.lotpeche_onema (ba_id) ON DELETE RESTRICT ON UPDATE CASCADE 
     1003) INHERITS (dbeel.biological_characteristic); 
     1004-- TODO: insert trigger 
     1005 
     1006-- Lt min --> lot G et lot L 
     1007INSERT INTO onema.lotpeche_biol_charac_onema 
     1008        SELECT  
     1009                 uuid_generate_v4() AS bc_id, 
     1010                 ba_id AS bc_ba_id,  
     1011                 biological_characteristic_type.no_id AS bc_no_characteristic_type,  
     1012                 value_type.no_id AS  bc_no_value_type,  
     1013                lo_taillemin/10 AS  bc_numvalue 
     1014        FROM    onema.lotpeche_onema, 
     1015                dbeel_nomenclature.biological_characteristic_type,  
     1016                dbeel_nomenclature.value_type 
     1017        WHERE  
     1018                (lo_cd_type = 1059 OR lo_cd_type =1061)   
     1019                AND lo_taillemin>0  
     1020                AND biological_characteristic_type.no_name = 'Lower length' 
     1021                AND value_type.no_name = 'Class value'; 
     1022 
     1023-- Lt max --> lot G et lot L 
     1024INSERT INTO onema.lotpeche_biol_charac_onema 
     1025        SELECT  
     1026                 uuid_generate_v4() AS bc_id, 
     1027                 ba_id AS bc_ba_id,  
     1028                 biological_characteristic_type.no_id AS bc_no_characteristic_type,  
     1029                 value_type.no_id AS  bc_no_value_type,  
     1030                 lo_taillemax/10 AS bc_numvalue 
     1031        FROM    onema.lotpeche_onema,  
     1032                dbeel_nomenclature.biological_characteristic_type,  
     1033                dbeel_nomenclature.value_type 
     1034        WHERE  
     1035                (lo_cd_type = 1059 OR lo_cd_type =1061)   
     1036                AND lo_taillemin>0  
     1037                AND biological_characteristic_type.no_name = 'Upper length'  
     1038                AND value_type.no_name = 'Class value'; 
     1039 
     1040-- P total --> lot G, lot I, lot L 
     1041INSERT INTO onema.lotpeche_biol_charac_onema 
     1042        SELECT  
     1043                 uuid_generate_v4() AS bc_id, 
     1044                 ba_id AS bc_ba_id,  
     1045                 biological_characteristic_type.no_id AS bc_no_characteristic_type,  
     1046                 value_type.no_id AS  bc_no_value_type,                   
     1047                 lo_poids AS biological_characteristic_numvalue 
     1048        FROM onema.lotpeche_onema,  
     1049        dbeel_nomenclature.biological_characteristic_type,  
     1050        dbeel_nomenclature.value_type 
     1051        WHERE  
     1052                (lo_cd_type = 1059 OR lo_cd_type =1060 OR lo_cd_type =1061)   
     1053                AND lo_poids>0  
     1054                AND lo_cd_codeestimpoids=752  -- only real weight 
     1055                AND biological_characteristic_type.no_name = 'Weight'  
     1056                AND value_type.no_name = 'Cumulated data' 
     1057;-- 3527 
     1058 
     1059-- L individual --> lot N 
     1060 
     1061INSERT INTO onema.lotpeche_biol_charac_onema 
     1062        SELECT  
     1063                 uuid_generate_v4() AS bc_id, 
     1064                 ba_id AS bc_ba_id,  
     1065                 biological_characteristic_type.no_id AS bc_no_characteristic_type,  
     1066                 value_type.no_id AS  bc_no_value_type,          
     1067                 lo_taille/10 AS biological_characteristic_numvalue 
     1068        FROM onema.lotpeche_onema, dbeel_nomenclature.biological_characteristic_type, dbeel_nomenclature.value_type 
     1069        WHERE  
     1070                lo_cd_type = 1062  AND lo_taille>0 AND 
     1071                biological_characteristic_type.no_name = 'Length' AND 
     1072                value_type.no_name = 'Raw data or Individual data' 
     1073; --161428 
     1074 
     1075-- P individual --> lot N 
     1076INSERT INTO onema.lotpeche_biol_charac_onema 
     1077        SELECT  
     1078                uuid_generate_v4() AS bc_id, 
     1079                 ba_id AS bc_ba_id,  
     1080                 biological_characteristic_type.no_id AS bc_no_characteristic_type,  
     1081                 value_type.no_id AS  bc_no_value_type,          
     1082                 lo_poids AS biological_characteristic_numvalue 
     1083        FROM onema.lotpeche_onema, dbeel_nomenclature.biological_characteristic_type, dbeel_nomenclature.value_type 
     1084        WHERE  
     1085                lo_cd_type = 1062  
     1086                AND lo_poids>0  
     1087                AND lo_cd_codeestimpoids=752 -- only real weight  
     1088                AND biological_characteristic_type.no_name = 'Weight'  
     1089                AND value_type.no_name = 'Raw data or Individual data' -- 77189 
     1090;  
     1091 
     1092-- select * from onema.lotpeche_biol_charac_onema --280018 rows 
     1093 
     1094--------------------------------------------------------------------------------------- 
     1095-- mensurationindiv 
     1096------------------------------------------------------------------------------------ 
     1097DROP TABLE if exists onema.mensurationindiv_onema CASCADE; 
     1098CREATE TABLE onema.mensurationindiv_onema ( 
     1099        LIKE onema.mensurationindiv, 
     1100                CONSTRAINT pk_mensindivonema_id PRIMARY KEY (ba_id), 
     1101        CONSTRAINT fk_mensindivonema_ba_no_species_id FOREIGN KEY (ba_no_species)  
     1102                REFERENCES dbeel_nomenclature.species (no_id) MATCH SIMPLE 
     1103                ON DELETE RESTRICT ON UPDATE CASCADE, 
     1104        CONSTRAINT fk_mensindivonema_ba_no_stage_id FOREIGN KEY (ba_no_stage)  
     1105                REFERENCES dbeel_nomenclature.stage (no_id) MATCH SIMPLE 
     1106                ON DELETE RESTRICT ON UPDATE CASCADE,    
     1107        CONSTRAINT fk_mensindivonema_ba_value_type FOREIGN KEY (ba_no_value_type) 
     1108                REFERENCES dbeel_nomenclature.value_type (no_id) 
     1109                ON DELETE RESTRICT ON UPDATE CASCADE,    
     1110        CONSTRAINT fk_mensindivonema_ba_no_biological_characteristic_type       FOREIGN KEY (ba_no_biological_characteristic_type) 
     1111                REFERENCES dbeel_nomenclature.biological_characteristic_type (no_id) 
     1112                ON DELETE RESTRICT ON UPDATE CASCADE,    
     1113        CONSTRAINT fk_mensindivonema_ba_no_individual_status FOREIGN KEY (ba_no_individual_status) 
     1114                REFERENCES dbeel_nomenclature.individual_status(no_id) MATCH SIMPLE 
     1115                ON DELETE RESTRICT ON UPDATE CASCADE,    
     1116        CONSTRAINT fk_mensindivonema_ba_ob_id FOREIGN KEY (ba_ob_id) 
     1117                REFERENCES onema.operation_onema(ob_id) --setting the constraint to the uppermost level dbeel.observations(ob_id) does not work ! 
     1118                ON DELETE RESTRICT ON UPDATE CASCADE 
     1119--      CONSTRAINT fk_lopeo_ba_ba_id FOREIGN KEY (ba_ba_id) 
     1120--              REFERENCES dbeel.batch(ba_id) -- Il ne peut pas y avoir de contraintes de clé étrangères dans la table 
     1121--              ON DELETE RESTRICT ON UPDATE CASCADE 
     1122        ) INHERITS (dbeel.batch); 
     1123 
     1124 
     1125(select * from  onema.operation_onema  
     1126        join onema.lotpeche_onema  on ob_id=ba_ob_id  
     1127        join onema.mensurationindiv on mi_lo_id=lotpeche_onema.lo_id limit 10) as sub 
     1128 
     1129 
     1130INSERT INTO onema.mensurationindiv_onema 
     1131        SELECT uuid_generate_v4() AS ba_id, 
     1132        species.no_id AS ba_no_species, 
     1133        stage.no_id AS ba_no_stage, 
     1134        value_type.no_id AS ba_no_value_type, 
     1135        biological_characteristic_type.no_id AS ba_no_biological_characteristic_type, 
     1136        1 AS ba_quantity, 
     1137        individual_status.no_id AS ba_no_individual_status, 
     1138        4 AS ba_batch_level, 
     1139        joineel. * --contains ba_ob_id and ba_ba_id 
     1140        FROM dbeel_nomenclature.species,  
     1141        dbeel_nomenclature.stage,  
     1142        dbeel_nomenclature.biological_characteristic_type, 
     1143        dbeel_nomenclature.value_type, 
     1144        dbeel_nomenclature.individual_status,  
     1145        (select ob_id as ba_ob_id,ba_id AS ba_ba_id, mensurationindiv.* from onema.operation_onema  
     1146        join onema.lotpeche_onema  on ob_id=ba_ob_id  
     1147        join onema.mensurationindiv on mi_lo_id=lotpeche_onema.lo_id  
     1148        where lo_ta_id=2) as joineel 
     1149        WHERE species.no_name='Anguilla anguilla'  
     1150        AND stage.no_name='Yellow & silver eel mixed'  
     1151        AND biological_characteristic_type.no_name='Number'  
     1152        AND individual_status.no_name='Alive'  
     1153        AND value_type.no_name='Raw data or Individual data';--42253 lines 
     1154 
     1155-- select * from onema.mensurationindiv_onema  
     1156 
     1157--------------------------------------------------------------------------------------- 
     1158-- Biological characteristic for mensurationindiv 
     1159 
     1160DROP TABLE if exists onema.mensurationindiv_biol_charac_onema CASCADE; 
     1161CREATE TABLE onema.mensurationindiv_biol_charac_onema ( 
     1162        CONSTRAINT pk_mensindivbiocho_id PRIMARY KEY (bc_id), 
     1163        CONSTRAINT fk_mensindivbiocho_bc_characteristic_type FOREIGN KEY (bc_no_characteristic_type) 
     1164                REFERENCES dbeel_nomenclature.biological_characteristic_type (no_id) ON DELETE RESTRICT ON UPDATE CASCADE, 
     1165        CONSTRAINT fk_mensindivbiocho_bc_value_type     FOREIGN KEY (bc_no_value_type) 
     1166                REFERENCES dbeel_nomenclature.value_type (no_id) ON DELETE RESTRICT ON UPDATE CASCADE, 
     1167        CONSTRAINT fk_mensindivbiocho_bc_ba_id FOREIGN KEY (bc_ba_id) 
     1168                REFERENCES onema.mensurationindiv_onema (ba_id) ON DELETE RESTRICT ON UPDATE CASCADE 
     1169)INHERITS (dbeel.biological_characteristic); 
     1170-- TODO: insert trigger 
     1171 
     1172INSERT INTO onema.mensurationindiv_biol_charac_onema 
     1173        SELECT  
     1174                 uuid_generate_v4() AS bc_id,  
     1175                 ba_id AS bc_ba_id,  
     1176                 biological_characteristic_type.no_id AS bc_no_characteristic_type,  
     1177                 value_type.no_id AS bc_no_value_type,  
     1178                 mi_poids AS bc_numvalue 
     1179        FROM onema.mensurationindiv_onema,  
     1180        dbeel_nomenclature.biological_characteristic_type,  
     1181        dbeel_nomenclature.value_type 
     1182        WHERE  
     1183                mi_cd_codeestimationpoids = 752  
     1184                AND mi_poids>0  
     1185                AND biological_characteristic_type.no_name = 'Weight'  
     1186                AND value_type.no_name = 'Raw data or Individual data' 
     1187; --146 lines 
     1188 
     1189INSERT INTO onema.mensurationindiv_biol_charac_onema 
     1190        SELECT  
     1191                uuid_generate_v4() AS bc_id,  
     1192                 ba_id AS bc_ba_id,  
     1193                 biological_characteristic_type.no_id AS bc_no_characteristic_type,  
     1194                 value_type.no_id AS bc_no_value_type,  
     1195                 mi_taille AS bc_numvalue 
     1196        FROM onema.mensurationindiv_onema,  
     1197        dbeel_nomenclature.biological_characteristic_type,  
     1198        dbeel_nomenclature.value_type 
     1199        WHERE  
     1200                mi_taille>0  
     1201                AND biological_characteristic_type.no_name = 'Length'  
     1202                AND value_type.no_name = 'Raw data or Individual data' 
     1203; --42252 (contre 40721 avant) 
     1204 
     1205-- select * from onema.operation_onema  order by  ob_starting_date 
     1206-- select * from dbeel.electrofishing where extract(year from ob_starting_date) >2010 order by ob_starting_date -- c'est ok elles sont dans la dbeel 
     1207 
     1208}}}