add link to tps trans to find any potential import conflicts

This commit is contained in:
Paul Trowbridge 2017-10-16 00:14:05 -04:00
parent 668ca9f44a
commit ac4d9f68d5

View File

@ -49,12 +49,14 @@ $$;
--*******************************************
--this needs to aggregate on id sequence
--*******************************************
WITH pending_list AS (
SELECT
---creates a key value pair and then aggregates rows of key value pairs
jsonb_object_agg(
(ae.e::text[])[1], --the key name
(row_to_json(i)::jsonb) #> ae.e::text[] --get the target value from the key from the csv row that has been converted to json
) json_key,
row_to_json(i) rec,
srce,
--ae.rn,
id
@ -64,7 +66,22 @@ FROM
s.srce = 'DCARD'
LEFT JOIN LATERAL JSONB_ARRAY_ELEMENTS_TEXT(defn->'unique_constraint'->'fields') WITH ORDINALITY ae(e, rn) ON TRUE
GROUP BY
i.*,
srce,
id
ORDER BY
id
)
, matched_tps AS (
SELECT
*
FROM
pending_list pl
INNER JOIN tps.trans t ON
t.srce = pl.srce
AND t.rec @> pl.json_key
)
SELECT * FROM matched_tps;
-- need to compare against and tps matches
-- therefore need to apply keyset to tps rows