| 28 | {{{ |
| 29 | /* |
| 30 | SCRIPT DE CREATION D'UN TABLEAU UNIQUE DES RESULTATS |
| 31 | 6 avril 2012 Cédric Briand Céline Jouanin |
| 32 | */ |
| 33 | |
| 34 | -- pour voir les données du modèle, ci dessous seules certaines colonnes de résultats sont retenues |
| 35 | |
| 36 | select * from rht.model_mod |
| 37 | |
| 38 | -- le script utilise la fonction crosstab (text,text) pour passer d'un format 'long' a un format 'court' (données en colonnes) |
| 39 | -- comme crosstab est une fonction renvoyant un setof record, il faut nommer et typer les colonnes de sortie as.... |
| 40 | |
| 41 | DROP TABLE IF EXISTS rht.crosstab_rhtvs2; |
| 42 | CREATE TABLE rht.crosstab_rhtvs2 as ( |
| 43 | SELECT |
| 44 | rhtvs2.id_drain, |
| 45 | crosstab.largeur, |
| 46 | crosstab.surface, |
| 47 | crosstab.ers_id_drain, |
| 48 | crosstab.exutoire, |
| 49 | crosstab.gamma, |
| 50 | crosstab.delta, |
| 51 | crosstab.densite, |
| 52 | crosstab.abondance, |
| 53 | rhtvs2.the_geom, |
| 54 | rhtvs2.dmer, |
| 55 | rhtvs2.dsource, |
| 56 | rhtvs2.cumnbbar from rht.rhtvs2 left join |
| 57 | (SELECT * FROM crosstab('select res_id_drain, res_mod_id,res_value from rht.resultmodel |
| 58 | where res_mod_id in (24,23,25,26,4,5,6,27) |
| 59 | order by 1,2', |
| 60 | 'select mod_id from rht.model_mod where mod_id in (24,23,25,26,4,5,6,27) order by mod_id') |
| 61 | AS ct(id_drain integer, |
| 62 | largeur numeric, |
| 63 | surface numeric, |
| 64 | ers_id_drain numeric, |
| 65 | gamma numeric, |
| 66 | delta numeric, |
| 67 | densite numeric, |
| 68 | abondance numeric, |
| 69 | exutoire numeric) |
| 70 | )as crosstab |
| 71 | on rhtvs2.id_drain=crosstab.id_drain); |
| 72 | |
| 73 | comment on table rht.crosstab_rhtvs2 is 'table crée le 6 avril 2012 a partir des résultats définitifs d''EDA'; |
| 74 | -- creation des clés et des index qui vont bien |
| 75 | alter table rht.crosstab_rhtvs2 add constraint c_pk_crosstab_rhtvs2 PRIMARY KEY (id_drain); |
| 76 | CREATE INDEX crosstab_rhtvs2_index |
| 77 | ON rht.crosstab_rhtvs2 |
| 78 | USING btree |
| 79 | (id_drain); |
| 80 | CREATE INDEX crosstab_rhtvs2_gistindex |
| 81 | ON rht.rhtvs2 |
| 82 | USING gist |
| 83 | (the_geom); |
| 84 | |
| 85 | -- code dump |
| 86 | -- pg_dump -U postgres -f 'v_rht_model_mod.sql' --table rht.crosstab.rhtvs2 eda2.0_RHT |
| 87 | |
| 88 | comment on column rht.crosstab_rhtvs2.surface is 'surface en km²'; |
| 89 | comment on column rht.crosstab_rhtvs2.largeur is 'largeur en m'; |
| 90 | |
| 91 | cd d:\CelineJouanin\export_table\version2 |
| 92 | C:\"Program Files"\PostgreSQL\8.4\bin\pg_dump -U postgres -p 5432 -t rht.crosstab_rhtvs2 eda2.0_RHT> v_rht_model_mod.sql |
| 93 | }}} |