----------------------------------------------------build the column list of the temp table----------------------------------------------------------------
----------------------------------------------------add create table verbage in front of column list--------------------------------------------------------
----------------------------------------------------do the insert-------------------------------------------------------------------------------------------
-----------insert pending rows that have key with no trans match-----------------------------------------------------------------------------------
--need to look into mapping the transactions prior to loading
, inserted AS (
INSERT INTO
tps.trans (srce, rec)
SELECT
pl.srce
,pl.rec
FROM
pending_list pl
INNER JOIN unmatched_keys u ON
u.json_key = pl.json_key
ORDER BY
pl.id ASC
----this conflict is only if an exact duplicate rec json happens, which will be rejected
----therefore, records may not be inserted due to ay matches with certain json fields, or if the entire json is a duplicate, reason is not specified
RETURNING *
)
-----------list of records not inserted--------------------------------------------------------------------------------------------------------------
, not_inserted AS (
SELECT
srce
,rec
FROM
pending_list
EXCEPT ALL
SELECT
srce
,rec
FROM
inserted
)
--------insert to log-------------------------------------------------------------------------------------------------------------------------------------
--------summarize records not inserted-------------------+------------------------------------------------------------------------------------------------