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 --this needs to aggregate on id sequence
--******************************************* --*******************************************
WITH pending_list AS (
SELECT SELECT
---creates a key value pair and then aggregates rows of key value pairs ---creates a key value pair and then aggregates rows of key value pairs
jsonb_object_agg( jsonb_object_agg(
(ae.e::text[])[1], --the key name (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 (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, ) json_key,
row_to_json(i) rec,
srce, srce,
--ae.rn, --ae.rn,
id id
@ -64,7 +66,22 @@ FROM
s.srce = 'DCARD' s.srce = 'DCARD'
LEFT JOIN LATERAL JSONB_ARRAY_ELEMENTS_TEXT(defn->'unique_constraint'->'fields') WITH ORDINALITY ae(e, rn) ON TRUE LEFT JOIN LATERAL JSONB_ARRAY_ELEMENTS_TEXT(defn->'unique_constraint'->'fields') WITH ORDINALITY ae(e, rn) ON TRUE
GROUP BY GROUP BY
i.*,
srce, srce,
id id
ORDER BY ORDER BY
id 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