diff --git a/srce_defn.pgsql b/srce_defn.pgsql new file mode 100644 index 0000000..79046fb --- /dev/null +++ b/srce_defn.pgsql @@ -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 \ No newline at end of file diff --git a/trans_log_template.pgsql b/trans_log_template.pgsql new file mode 100644 index 0000000..07b958e --- /dev/null +++ b/trans_log_template.pgsql @@ -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 +) \ No newline at end of file diff --git a/ubm_data.sql b/ubm_data.sql index e4b60dc..d63c435 100644 --- a/ubm_data.sql +++ b/ubm_data.sql @@ -415,6 +415,21 @@ INSERT INTO map_rv (srce, target, retval, map) VALUES ('DCARD', 'First 20', '{"f -- Data for Name: trans; Type: TABLE DATA; Schema: tps; Owner: - -- +INSERT INTO trans (id, srce, rec, map) VALUES (2639, 'DCARD', '{"id": 23, "Amount": "1.19", "Category": "Merchandise", "Post Date": "2017-10-15", "Description": "DISCOUNT DRUG MART 32 STOW OH", "Trans. Date": "2017-10-15"}', NULL); +INSERT INTO trans (id, srce, rec, map) VALUES (2640, 'DCARD', '{"id": 24, "Amount": "12.86", "Category": "Automotive", "Post Date": "2017-10-16", "Description": "AUTOZONE #1941 STREETSBORO OH", "Trans. Date": "2017-10-16"}', NULL); +INSERT INTO trans (id, srce, rec, map) VALUES (2641, 'DCARD', '{"id": 25, "Amount": "6.50", "Category": "Restaurants", "Post Date": "2017-10-16", "Description": "EL CAMPESINO STOW OH", "Trans. Date": "2017-10-16"}', NULL); +INSERT INTO trans (id, srce, rec, map) VALUES (2642, 'DCARD', '{"id": 26, "Amount": "60.00", "Category": "Services", "Post Date": "2017-10-16", "Description": "REMEMBERNHU 402-935-7733 IA", "Trans. Date": "2017-10-16"}', NULL); +INSERT INTO trans (id, srce, rec, map) VALUES (2643, 'DCARD', '{"id": 27, "Amount": "38.45", "Category": "Gasoline", "Post Date": "2017-10-17", "Description": "SPEEDWAY 03686 496 STOW OH", "Trans. Date": "2017-10-17"}', NULL); +INSERT INTO trans (id, srce, rec, map) VALUES (2644, 'DCARD', '{"id": 28, "Amount": "3.28", "Category": "Supermarkets", "Post Date": "2017-10-17", "Description": "WALMART GROCERY 800-966-6546 AR", "Trans. Date": "2017-10-17"}', NULL); +INSERT INTO trans (id, srce, rec, map) VALUES (2645, 'DCARD', '{"id": 29, "Amount": "234.07", "Category": "Supermarkets", "Post Date": "2017-10-17", "Description": "WALMART GROCERY 800-966-6546 AR", "Trans. Date": "2017-10-17"}', NULL); +INSERT INTO trans (id, srce, rec, map) VALUES (2646, 'DCARD', '{"id": 30, "Amount": "21.35", "Category": "Merchandise", "Post Date": "2017-10-18", "Description": "DOLLAR TREE STOW OH", "Trans. Date": "2017-10-18"}', NULL); +INSERT INTO trans (id, srce, rec, map) VALUES (2647, 'DCARD', '{"id": 31, "Amount": "10.20", "Category": "Supermarkets", "Post Date": "2017-10-18", "Description": "GIANT-EAGLE #4096 STOW OH", "Trans. Date": "2017-10-18"}', NULL); +INSERT INTO trans (id, srce, rec, map) VALUES (2648, 'DCARD', '{"id": 32, "Amount": "30.94", "Category": "Merchandise", "Post Date": "2017-10-18", "Description": "TARGET STOW OH", "Trans. Date": "2017-10-18"}', NULL); +INSERT INTO trans (id, srce, rec, map) VALUES (2649, 'DCARD', '{"id": 33, "Amount": "18.14", "Category": "Restaurants", "Post Date": "2017-10-19", "Description": "ARBYS #1831 STOW STOW OH", "Trans. Date": "2017-10-19"}', NULL); +INSERT INTO trans (id, srce, rec, map) VALUES (2650, 'DCARD', '{"id": 34, "Amount": "19.60", "Category": "Merchandise", "Post Date": "2017-10-19", "Description": "DISCOUNT DRUG MART 32 STOW OH", "Trans. Date": "2017-10-19"}', NULL); +INSERT INTO trans (id, srce, rec, map) VALUES (2651, 'DCARD', '{"id": 35, "Amount": "78.36", "Category": "Merchandise", "Post Date": "2017-10-20", "Description": "TARGET STREETSBORO OH", "Trans. Date": "2017-10-20"}', NULL); +INSERT INTO trans (id, srce, rec, map) VALUES (2652, 'DCARD', '{"id": 36, "Amount": "28.42", "Category": "Restaurants", "Post Date": "2017-10-21", "Description": "ARBYS #1831 STOW STOW OH", "Trans. Date": "2017-10-21"}', NULL); +INSERT INTO trans (id, srce, rec, map) VALUES (2653, 'DCARD', '{"id": 37, "Amount": "23.75", "Category": "Merchandise", "Post Date": "2017-10-21", "Description": "DISCOUNT DRUG MART 32 STOW OH", "Trans. Date": "2017-10-21"}', NULL); INSERT INTO trans (id, srce, rec, map) VALUES (2152, 'HUNT', '{"Date": "2017-05-02", "Memo": "SUBSTITUTE CHECK", "Amount": "-1000", "Payee Name": "", "Category Name": "", "Reference Number": 1800}', NULL); INSERT INTO trans (id, srce, rec, map) VALUES (2128, 'HUNT', '{"Date": "2017-06-07", "Memo": "SUBSTITUTE CHECK", "Amount": "-700", "Payee Name": "", "Category Name": "", "Reference Number": 1808}', NULL); INSERT INTO trans (id, srce, rec, map) VALUES (94, 'DCARD', '{"Amount": "119.03", "Category": "Merchandise", "Post Date": "2017-05-07", "Description": "TARGET STOW OH", "Trans. Date": "2017-05-05"}', '{"f20": "TARGET STOW OH", "party": "Target", "reason": "Groceries"}'); @@ -3054,6 +3069,12 @@ INSERT INTO trans (id, srce, rec, map) VALUES (2092, 'DCARD', '{"Amount": "14.00 INSERT INTO trans (id, srce, rec, map) VALUES (2093, 'DCARD', '{"Amount": "77.47", "Category": "Merchandise", "Post Date": "2017-08-07", "Description": "WAL-MART SC - #2313 STREETSBORO OH", "Trans. Date": "2017-08-04"}', '{"f20": "WAL-MART SC - #2313 ", "party": "Wal-Mart", "reason": "Home Supplies"}'); +-- +-- Data for Name: trans_log; Type: TABLE DATA; Schema: tps; Owner: - +-- + + + SET search_path = evt, pg_catalog; -- @@ -3069,7 +3090,14 @@ SET search_path = tps, pg_catalog; -- Name: trans_id_seq; Type: SEQUENCE SET; Schema: tps; Owner: - -- -SELECT pg_catalog.setval('trans_id_seq', 2638, true); +SELECT pg_catalog.setval('trans_id_seq', 2653, true); + + +-- +-- Name: trans_log_id_seq; Type: SEQUENCE SET; Schema: tps; Owner: - +-- + +SELECT pg_catalog.setval('trans_log_id_seq', 1, false); -- diff --git a/ubm_schema.sql b/ubm_schema.sql index c3ec511..5b3abc6 100644 --- a/ubm_schema.sql +++ b/ubm_schema.sql @@ -2,8 +2,8 @@ -- PostgreSQL database dump -- --- Dumped from database version 10rc1 --- Dumped by pg_dump version 10rc1 +-- Dumped from database version 10beta4 +-- Dumped by pg_dump version 10beta4 SET statement_timeout = 0; SET lock_timeout = 0; @@ -56,20 +56,6 @@ CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language'; --- --- Name: plprofiler; Type: EXTENSION; Schema: -; Owner: - --- - -CREATE EXTENSION IF NOT EXISTS plprofiler WITH SCHEMA public; - - --- --- Name: EXTENSION plprofiler; Type: COMMENT; Schema: -; Owner: - --- - -COMMENT ON EXTENSION plprofiler IS 'server-side support for profiling PL/pgSQL functions'; - - SET search_path = tps, pg_catalog; -- @@ -109,6 +95,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: - -- @@ -227,6 +237,30 @@ ALTER TABLE trans ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY ( ); +-- +-- Name: trans_log; Type: TABLE; Schema: tps; Owner: - +-- + +CREATE TABLE trans_log ( + id integer NOT NULL, + info jsonb +); + + +-- +-- Name: trans_log_id_seq; Type: SEQUENCE; Schema: tps; Owner: - +-- + +ALTER TABLE trans_log ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY ( + SEQUENCE NAME trans_log_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1 +); + + SET search_path = evt, pg_catalog; -- @@ -263,6 +297,14 @@ ALTER TABLE ONLY srce ADD CONSTRAINT srce_pkey PRIMARY KEY (srce); +-- +-- Name: trans_log trans_log_pkey; Type: CONSTRAINT; Schema: tps; Owner: - +-- + +ALTER TABLE ONLY trans_log + ADD CONSTRAINT trans_log_pkey PRIMARY KEY (id); + + -- -- Name: trans trans_pkey; Type: CONSTRAINT; Schema: tps; Owner: - --