From 6aae1553c66056d715dd810ffc827424379b82f7 Mon Sep 17 00:00:00 2001 From: Sweaty Handshake Date: Thu, 24 Oct 2024 20:30:06 +0000 Subject: [PATCH] Make view unique by primary keys --- dbt/models/reporting/reporting.vw_pin_school_impact.sql | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dbt/models/reporting/reporting.vw_pin_school_impact.sql b/dbt/models/reporting/reporting.vw_pin_school_impact.sql index e4c6ae61e..6240f75cc 100644 --- a/dbt/models/reporting/reporting.vw_pin_school_impact.sql +++ b/dbt/models/reporting/reporting.vw_pin_school_impact.sql @@ -50,12 +50,14 @@ WITH ranking AS ( WHERE info.major_type = 'SCHOOL' ), +-- We need to use array_agg for this CTE since some parcels can be in multiple +-- SSAs tif_ssa AS ( SELECT pin.pin, pin.year, - info.agency_name, - info.minor_type + info.minor_type, + ARRAY_AGG(info.agency_name) AS agency_name FROM {{ source('tax', 'pin') }} AS pin LEFT JOIN {{ source('tax', 'tax_code') }} AS code ON pin.tax_code_num = code.tax_code_num @@ -63,6 +65,7 @@ tif_ssa AS ( INNER JOIN {{ source('tax', 'agency_info') }} AS info ON code.agency_num = info.agency_num + GROUP BY pin.pin, pin.year, info.minor_type ) SELECT