tps/srce_defn.pgsql

24 lines
529 B
Plaintext
Raw Normal View History

\timing
/*
2017-10-24 17:37:20 -04:00
WITH
ext AS (
SELECT
srce
,defn->'unique_constraint'->>'fields'
,ARRAY(SELECT ae.e::text[] FROM jsonb_array_elements_text(defn->'unique_constraint'->'fields') ae(e)) text_array
2017-10-24 17:37:20 -04:00
FROM
tps.srce
--add where clause for targeted source
2017-10-24 17:37:20 -04:00
)
*/
SELECT COUNT(*) FROM
(
SELECT DISTINCT
t.srce
,(SELECT JSONB_OBJECT_agg(ae.e,rec #> ae.e::text[]) FROM jsonb_array_elements_text(defn->'unique_constraint'->'fields') ae(e)) ja
2017-10-24 17:37:20 -04:00
FROM
tps.trans t
INNER JOIN tps.srce s ON
s.srce = t.srce
) X