From c81a7c7dc48522683abdd4bb0ac7ca5ba8060f58 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Fri, 13 Oct 2017 17:17:56 -0400 Subject: [PATCH] extract key at import --- srce.pgsql | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/srce.pgsql b/srce.pgsql index beaa58a..2fef279 100644 --- a/srce.pgsql +++ b/srce.pgsql @@ -15,7 +15,7 @@ begin --unwrap the schema definition array LEFT JOIN LATERAL jsonb_populate_recordset(null::tps.srce_defn_schema, defn->'schema') prs ON TRUE WHERE - srce = 'PNCO' + srce = 'PNCL' GROUP BY srce; @@ -31,14 +31,31 @@ begin EXECUTE _t; + COPY csv_i FROM 'C:\Users\ptrowbridge\Documents\OneDrive - The HC Companies, Inc\Cash\build_hist\pncl.csv' WITH (HEADER TRUE,DELIMITER ',', FORMAT CSV, ENCODING 'SQL_ASCII',QUOTE '"'); + end $$; ---SELECT * FROM csv_i; - -COPY csv_i FROM 'C:\Users\ptrowbridge\Documents\OneDrive - The HC Companies, Inc\Cash\build_hist\full_dl\15Q1bal.csv' WITH (HEADER TRUE,DELIMITER ',', FORMAT CSV, ENCODING 'SQL_ASCII',QUOTE '"'); +--SELECT row_to_json(csv_i) FROM csv_i; +/* INSERT INTO tps.trans (srce, rec) SELECT - 'PNCO', row_to_json(csv_i) FROM csv_i; \ No newline at end of file + 'PNCO', row_to_json(csv_i) FROM csv_i; +*/ + + +SELECT + (row_to_json(i)::jsonb) #> ae.e::text[], + srce, + defn->'unique_constraint'->'type', + defn->'unique_constraint'->'fields', + ae.e, + ae.rn +FROM + csv_i i + INNER JOIN tps.srce s ON + s.srce = 'PNCL' + LEFT JOIN LATERAL JSONB_ARRAY_ELEMENTS_TEXT(defn->'unique_constraint'->'fields') WITH ORDINALITY ae(e, rn) ON TRUE +LIMIT 10 \ No newline at end of file