diff --git a/srce.pgsql b/srce.pgsql index aa7a730..adc4454 100644 --- a/srce.pgsql +++ b/srce.pgsql @@ -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 \ No newline at end of file + 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 \ No newline at end of file