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,8 +89,8 @@ 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
RETURNING *
)
----records not inserted------
---------raw list of records not inserted----------
, not_inserted AS (
SELECT
srce
,rec
@ -103,4 +103,20 @@ SELECT
srce
,rec
FROM
inserted;
inserted
)
--------summarize records not inserted------------------
SELECT
t.srce
,(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
not_inserted t
INNER JOIN tps.srce s ON
s.srce = t.srce
LEFT JOIN LATERAL JSONB_ARRAY_ELEMENTS_TEXT(defn->'unique_constraint'->'fields') WITH ORDINALITY ae(e, rn) ON TRUE
GROUP BY
t.srce
,(ae.e::text[])[1];