Skip to content

Commit

Permalink
Update join_tracking_table_crossings_vw.sql (#599)
Browse files Browse the repository at this point in the history
* Add WCRP columns to wcrp_watersheds.csv

Column shows which wcrp the watershed belongs to

* Added migration files

db.v0.5.3 includes join_tracking_table_crossings_vw.sql and migrate.sh

* Add wcrp column to wcrp_watersheds

Added column in table creation

* Moved wcrp column creation

- Added statement to add the wcrp column to bcfishpass.wcrp_watersheds
- removed the change from db/v0.5.0/sql/tables/wcrp.sql

* run add column wcrp to wcrp_watersheds on all systems

* Update join_tracking_table_crossings_vw.sql

- Added right join so excluded structures with no feature in crossings_wcrp_vw show up in the joined table.

* Update join_tracking_table_crossings_vw.sql

- Modified join to include crossings in bcfishpass.crossings_wcrp_vw that are not in the tracking table but are in the WCRP and where all_spawningrearing_km > 0.

* Update join_tracking_table_crossings_vw.sql

Altered condition to ensure all features from the tracking table are in the joined output view.

---------

Co-authored-by: Simon Norris <snorris@hillcrestgeo.ca>
  • Loading branch information
andrewp-CWF and smnorris authored Nov 13, 2024
1 parent 51f47bd commit 66069a5
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions db/v0.5.3/sql/join_tracking_table_crossings_vw.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ as
$$
begin
execute format('create or replace view wcrp_%I.combined_tracking_table_crossings_wcrp_vw_%I as
select
tt.barrier_id,
cv.crossing_source,
select
case
when tt.barrier_id is not null then tt.barrier_id
else cv.aggregated_crossings_id
end as barrier_id,
cv.crossing_source,
cv.crossing_feature_type,
cv.pscis_status,
cv.crossing_type_code,
Expand Down Expand Up @@ -114,8 +117,14 @@ begin
tt.notes,
tt.supporting_links
from bcfishpass.crossings_wcrp_vw cv
right join wcrp_%I.combined_tracking_table_%I tt
on tt.barrier_id = cv.aggregated_crossings_id', p_wcrp, p_wcrp, p_wcrp, p_wcrp);
full outer join wcrp_%I.combined_tracking_table_%I tt
on tt.barrier_id = cv.aggregated_crossings_id
where (cv.watershed_group_code in
(select watershed_group_code
from bcfishpass.wcrp_watersheds
where wcrp ilike %L)
and cv.all_spawningrearing_km > 0)
or tt.barrier_id is not null', p_wcrp, p_wcrp, p_wcrp, p_wcrp, p_wcrp);
end
$$
language plpgsql;
Expand Down

0 comments on commit 66069a5

Please sign in to comment.