merge summary of records not inserted from pt branch

This commit is contained in:
Paul Trowbridge 2017-10-18 14:10:07 -04:00
parent 4f958485d5
commit 748d6ddb3c

View File

@ -89,18 +89,34 @@ WITH pending_list AS (
----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 ----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 * RETURNING *
) )
---------raw list of records not inserted----------
, not_inserted AS (
SELECT
srce
,rec
FROM
pending_list
----records not inserted------ EXCEPT ALL
SELECT
srce
,rec
FROM
inserted
)
--------summarize records not inserted------------------
SELECT SELECT
srce t.srce
,rec ,(ae.e::text[])[1] unq_constr
,MIN(rec #>> ae.e::text[]) min_text
,MAX(rec #>> ae.e::text[]) max_text
,JSONB_PRETTY(JSON_AGG(rec #> ae.e::text[] ORDER BY rec #>> ae.e::text[])::JSONB)
FROM FROM
pending_list not_inserted t
INNER JOIN tps.srce s ON
EXCEPT ALL s.srce = t.srce
LEFT JOIN LATERAL JSONB_ARRAY_ELEMENTS_TEXT(defn->'unique_constraint'->'fields') WITH ORDINALITY ae(e, rn) ON TRUE
SELECT GROUP BY
srce t.srce
,rec ,(ae.e::text[])[1];
FROM
inserted;