updates in progress
This commit is contained in:
parent
57fa123adf
commit
937cf38af1
@ -1,4 +1,4 @@
|
|||||||
|
\timing
|
||||||
SELECT
|
SELECT
|
||||||
r.*,
|
r.*,
|
||||||
SUM(r."Advances"+r."Adjustments"-r."Payments") OVER (ORDER BY r."Post Date" asc ,r."Reference #" asc)
|
SUM(r."Advances"+r."Adjustments"-r."Payments") OVER (ORDER BY r."Post Date" asc ,r."Reference #" asc)
|
||||||
|
18
srce.pgsql
18
srce.pgsql
@ -1,3 +1,6 @@
|
|||||||
|
SET auto_explain.log_min_duration = 0;
|
||||||
|
SHOW ALL;
|
||||||
|
|
||||||
\timing
|
\timing
|
||||||
|
|
||||||
/*--------------------------------------------------------
|
/*--------------------------------------------------------
|
||||||
@ -59,6 +62,12 @@ BEGIN
|
|||||||
|
|
||||||
EXECUTE _t;
|
EXECUTE _t;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
END
|
||||||
|
$$;
|
||||||
|
|
||||||
|
|
||||||
WITH
|
WITH
|
||||||
|
|
||||||
-------------for each imported row in the COPY table, genereate the json rec, and a column for the json key specified in the srce.defn-----------
|
-------------for each imported row in the COPY table, genereate the json rec, and a column for the json key specified in the srce.defn-----------
|
||||||
@ -77,7 +86,7 @@ BEGIN
|
|||||||
FROM
|
FROM
|
||||||
csv_i i
|
csv_i i
|
||||||
INNER JOIN tps.srce s ON
|
INNER JOIN tps.srce s ON
|
||||||
s.srce = _srce
|
s.srce = 'PNCO'
|
||||||
LEFT JOIN LATERAL JSONB_ARRAY_ELEMENTS_TEXT(defn->'unique_constraint'->'fields') WITH ORDINALITY ae(e, rn) ON TRUE
|
LEFT JOIN LATERAL JSONB_ARRAY_ELEMENTS_TEXT(defn->'unique_constraint'->'fields') WITH ORDINALITY ae(e, rn) ON TRUE
|
||||||
GROUP BY
|
GROUP BY
|
||||||
i.*,
|
i.*,
|
||||||
@ -159,8 +168,9 @@ BEGIN
|
|||||||
|
|
||||||
--------summarize records not inserted-------------------+------------------------------------------------------------------------------------------------
|
--------summarize records not inserted-------------------+------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
t.srce
|
jsonb_build_object('srce', t.srce) srce,
|
||||||
,(ae.e::text[])[1] unq_constr
|
,(ae.e::text[])[1] unq_constr
|
||||||
,MIN(rec #>> ae.e::text[]) min_text
|
,MIN(rec #>> ae.e::text[]) min_text
|
||||||
,MAX(rec #>> ae.e::text[]) max_text
|
,MAX(rec #>> ae.e::text[]) max_text
|
||||||
@ -173,6 +183,4 @@ BEGIN
|
|||||||
GROUP BY
|
GROUP BY
|
||||||
t.srce
|
t.srce
|
||||||
,(ae.e::text[])[1];
|
,(ae.e::text[])[1];
|
||||||
|
*/
|
||||||
END
|
|
||||||
$$;
|
|
17
srce_defn.pgsql
Normal file
17
srce_defn.pgsql
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
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)) txa
|
||||||
|
FROM
|
||||||
|
tps.srce
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
srce
|
||||||
|
,
|
||||||
|
public.jsonb_extract(rec,txa)
|
||||||
|
FROM
|
||||||
|
tps.trans
|
||||||
|
INNER JOIN ext ON
|
||||||
|
trans.srce = ext.srce
|
16
trans_log_template.pgsql
Normal file
16
trans_log_template.pgsql
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
SELECT
|
||||||
|
jsonb_pretty(
|
||||||
|
$$
|
||||||
|
{
|
||||||
|
"path":"C:\\users\\ptrowbridge\\downloads\\transsearchcsv.csv"
|
||||||
|
,"srce":"PNCC"
|
||||||
|
,"stamp":"2017-10-24 08:32:06.599067-04"
|
||||||
|
,"inserted":{
|
||||||
|
"keys":[
|
||||||
|
1,2,3,4,5,6,7
|
||||||
|
]
|
||||||
|
,"summary":""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$$::jsonb
|
||||||
|
)
|
@ -168,7 +168,7 @@ SET search_path = tps, pg_catalog;
|
|||||||
-- Name: trans_id_seq; Type: SEQUENCE SET; Schema: tps; Owner: -
|
-- Name: trans_id_seq; Type: SEQUENCE SET; Schema: tps; Owner: -
|
||||||
--
|
--
|
||||||
|
|
||||||
SELECT pg_catalog.setval('trans_id_seq', 1544069, true);
|
SELECT pg_catalog.setval('trans_id_seq', 1544080, true);
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
|
@ -119,6 +119,30 @@ CREATE TYPE srce_defn_schema AS (
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
SET search_path = public, pg_catalog;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Name: jsonb_extract(jsonb, text[]); Type: FUNCTION; Schema: public; Owner: -
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE FUNCTION jsonb_extract(rec jsonb, key_list text[]) RETURNS jsonb
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $$
|
||||||
|
DECLARE
|
||||||
|
t text;
|
||||||
|
j jsonb := '{}'::jsonb;
|
||||||
|
|
||||||
|
BEGIN
|
||||||
|
FOREACH t IN ARRAY key_list LOOP
|
||||||
|
j := j || jsonb_build_object(t,rec->t);
|
||||||
|
END LOOP;
|
||||||
|
RETURN j;
|
||||||
|
END;
|
||||||
|
$$;
|
||||||
|
|
||||||
|
|
||||||
|
SET search_path = tps, pg_catalog;
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: jsonb_concat(jsonb, jsonb); Type: FUNCTION; Schema: tps; Owner: -
|
-- Name: jsonb_concat(jsonb, jsonb); Type: FUNCTION; Schema: tps; Owner: -
|
||||||
--
|
--
|
||||||
|
Loading…
Reference in New Issue
Block a user