From edaed73e584acbeba77c1a6cef08b59a56c12727 Mon Sep 17 00:00:00 2001 From: Simon Norris Date: Tue, 15 Aug 2023 16:31:33 -0700 Subject: [PATCH] tighten up matching precision and discard duplicates when generating habitat endpoints --- .../user_habitat_classification_endpoints.sql | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/model/01_access/sql/user_habitat_classification_endpoints.sql b/model/01_access/sql/user_habitat_classification_endpoints.sql index 92993b86..0cb1eb03 100644 --- a/model/01_access/sql/user_habitat_classification_endpoints.sql +++ b/model/01_access/sql/user_habitat_classification_endpoints.sql @@ -18,15 +18,15 @@ INSERT INTO bcfishpass.user_habitat_classification_endpoints ) SELECT - h.blue_line_key, - h.downstream_route_measure, - s.linear_feature_id, - s.watershed_group_code + h.blue_line_key + ,h.downstream_route_measure + ,s.linear_feature_id + ,s.watershed_group_code FROM bcfishpass.user_habitat_classification h INNER JOIN whse_basemapping.fwa_stream_networks_sp s ON h.blue_line_key = s.blue_line_key -AND ROUND(s.downstream_route_measure::numeric) <= ROUND(h.downstream_route_measure::numeric) -AND ROUND(s.upstream_route_measure::numeric) > ROUND(h.downstream_route_measure::numeric) +AND ROUND(s.downstream_route_measure::numeric, 4) <= ROUND(h.downstream_route_measure::numeric, 4) +AND ROUND(s.upstream_route_measure::numeric, 4) > ROUND(h.downstream_route_measure::numeric, 4) UNION SELECT h.blue_line_key, @@ -36,5 +36,6 @@ SELECT FROM bcfishpass.user_habitat_classification h INNER JOIN whse_basemapping.fwa_stream_networks_sp s ON h.blue_line_key = s.blue_line_key -AND ROUND(s.downstream_route_measure::numeric) <= ROUND(h.upstream_route_measure::numeric) -AND ROUND(s.upstream_route_measure::numeric) > ROUND(h.upstream_route_measure::numeric); +AND ROUND(s.downstream_route_measure::numeric, 4) <= ROUND(h.upstream_route_measure::numeric, 4) +AND ROUND(s.upstream_route_measure::numeric, 4) > ROUND(h.upstream_route_measure::numeric, 4) +on conflict do nothing; -- the same blkey/measure may exist for different species, discard duplicates