| 211 | = specimen_tw_08_09 = |
| 212 | {{{ |
| 213 | drop table if exists wrbd.specimen_tw_08_09; |
| 214 | create table wrbd.specimen_tw_08_09( |
| 215 | estuary_name text, |
| 216 | date date, |
| 217 | easting integer, |
| 218 | northing integer, |
| 219 | lat numeric, |
| 220 | long numeric, |
| 221 | net_no text, |
| 222 | net_individual_no text, |
| 223 | net_type text, |
| 224 | length_cm numeric, |
| 225 | lifestage text, |
| 226 | sex text, |
| 227 | anguillicola_count integer, |
| 228 | weight_of_anguillicola_infection_g numeric, |
| 229 | otoliths_taken text, |
| 230 | otolith_box_no text, |
| 231 | stomach_contents text, |
| 232 | comment text); |
| 233 | |
| 234 | copy wrbd.specimen_tw_08_09 from 'C:/base/specimen_tw_08_09.csv' with CSV header delimiter as ';'; |
| 235 | -- a long and painfull process to verify that the names match, the cooridinates of the stations were sometimes different ex: Moy, I had only 39 station |
| 236 | select count (*) from wrbd.specimen_tw_08_09; --98 |
| 237 | select * from wrbd.specimen_tw_08_09 left join wrbd.station_st on (estuary_name)=(st_location); -- OK everything is filled in 98 |
| 238 | |
| 239 | drop table if exists wrbd.specimen_tw_08_09_1; |
| 240 | create table wrbd.specimen_tw_08_09_1 as( |
| 241 | select ss.st_id as fi_st_id,extract(year from date) as year, sr.* from wrbd.specimen_tw_08_09 sr left join wrbd.station_st ss on (estuary_name)=(st_location) |
| 242 | ); |
| 243 | drop table wrbd.specimen_tw_08_09; |
| 244 | -- le seul pivot possible est sur l'année |
| 245 | select * from wrbd.specimen_tw_08_09_1 join wrbd.operation_op on (op_st_id,op_year)=(fi_st_id,year) ;-- 98 |
| 246 | create table wrbd.specimen_tw_08_09_2 as( |
| 247 | select o.op_id as fi_ope_id, sr.* from wrbd.specimen_tw_08_09_1 sr join wrbd.operation_op o on (op_st_id,op_year)=(fi_st_id,year) |
| 248 | ); |
| 249 | drop table wrbd.specimen_tw_08_09_1; |
| 250 | --wrbd.specimen_tw_08_09_2 now contains operation and stations |
| 251 | |
| 252 | insert into wrbd.fish_fi( |
| 253 | fi_st_id, |
| 254 | fi_op_id, |
| 255 | fi_date, |
| 256 | fi_year, |
| 257 | fi_lifestage, |
| 258 | fi_retained, |
| 259 | fi_length, |
| 260 | fi_sex, |
| 261 | fi_anguillicola_nos, |
| 262 | fi_anguillicolaweight |
| 263 | ) |
| 264 | select |
| 265 | fi_st_id, |
| 266 | fi_ope_id, |
| 267 | date, |
| 268 | year, |
| 269 | lifestage, |
| 270 | case when otoliths_taken is not null then 'yes' |
| 271 | else 'no' end as retained, |
| 272 | length_cm, |
| 273 | sex, |
| 274 | anguillicola_count, |
| 275 | weight_of_anguillicola_infection_g |
| 276 | from wrbd.specimen_tw_08_09_2; |
| 277 | |
| 278 | drop table wrbd.specimen_tw_08_09_2; |
| 279 | |
| 280 | select count(*) from wrbd.fish_fi; --26148 |
| 281 | }}} |