From c6554831a13080578d39d2fa872b80bd259b90af Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Fri, 25 May 2018 10:25:09 -0400 Subject: [PATCH] make view creationg script use allj --- deploy/setup.sql | 4 +- interface/source_maint/test/srce.json | 86 +++++++++---------- interface/source_maint/test/srce_set_test.sql | 43 +--------- 3 files changed, 49 insertions(+), 84 deletions(-) diff --git a/deploy/setup.sql b/deploy/setup.sql index 34ce6c6..ae01962 100644 --- a/deploy/setup.sql +++ b/deploy/setup.sql @@ -224,7 +224,7 @@ LANGUAGE plpgsql; -----generate sql to create select based on schema DROP FUNCTION IF EXISTS tps.build_srce_view_sql(text, text); -CREATE FUNCTION tps.build_srce_view_sql(_srce text, _schema text) RETURNS TEXT +CREATE OR REPLACE FUNCTION tps.build_srce_view_sql(_srce text, _schema text) RETURNS TEXT AS $f$ DECLARE @@ -237,7 +237,7 @@ BEGIN _path:= ARRAY['schemas',_schema]::text[]; --_srce:= 'dcard'; SELECT - 'CREATE VIEW tpsv.'||_srce||'_'||_path[2]||' AS SELECT '||string_agg('(rec#>>'''||r.PATH::text||''')::'||r.type||' AS "'||r.column_name||'"',', ')||' FROM tps.trans WHERE srce = '''||_srce||'''' + 'CREATE VIEW tpsv.'||_srce||'_'||_path[2]||' AS SELECT '||string_agg('(allj#>>'''||r.PATH::text||''')::'||r.type||' AS "'||r.column_name||'"',', ')||' FROM tps.trans WHERE srce = '''||_srce||'''' INTO _sql FROM diff --git a/interface/source_maint/test/srce.json b/interface/source_maint/test/srce.json index b22fbf8..bea9cbd 100644 --- a/interface/source_maint/test/srce.json +++ b/interface/source_maint/test/srce.json @@ -1,75 +1,75 @@ { - "name":"dcard", - "source":"client_file", - "loading_function":"csv", - "constraint":[ + "name": "dcard", + "source": "client_file", + "loading_function": "csv", + "constraint": [ "{Trans. Date}", "{Post Date}", "{Description}" ], - "schemas":{ - "default":[ + "schemas": { + "default": [ { - "path":"{Trans. Date}", - "type":"date", - "column_name":"Trans. Date" + "path": "{Trans. Date}", + "type": "date", + "column_name": "Trans. Date" }, { - "path":"{Post Date}", - "type":"date", - "column_name":"Post Date" + "path": "{Post Date}", + "type": "date", + "column_name": "Post Date" }, { - "path":"{Description}", - "type":"text", - "column_name":"Description" + "path": "{Description}", + "type": "text", + "column_name": "Description" }, { - "path":"{Amount}", - "type":"numeric", - "column_name":"Amount" + "path": "{Amount}", + "type": "numeric", + "column_name": "Amount" }, { - "path":"{Category}", - "type":"text", - "column_name":"Category" + "path": "{Category}", + "type": "text", + "column_name": "Category" } ], - "mapped":[ + "mapped": [ { - "path":"{Trans. Date}", - "type":"date", - "column_name":"Trans. Date" + "path": "{Trans. Date}", + "type": "date", + "column_name": "Trans. Date" }, { - "path":"{Post Date}", - "type":"date", - "column_name":"Post Date" + "path": "{Post Date}", + "type": "date", + "column_name": "Post Date" }, { - "path":"{Description}", - "type":"text", - "column_name":"Description" + "path": "{Description}", + "type": "text", + "column_name": "Description" }, { - "path":"{Amount}", - "type":"numeric", - "column_name":"Amount" + "path": "{Amount}", + "type": "numeric", + "column_name": "Amount" }, { - "path":"{Category}", - "type":"text", - "column_name":"Category" + "path": "{Category}", + "type": "text", + "column_name": "Category" }, { - "path":"{party}", - "type":"text", - "column_name":"Party" + "path": "{party}", + "type": "text", + "column_name": "Party" }, { - "path":"{reason}", - "type":"text", - "column_name":"Reason" + "path": "{reason}", + "type": "text", + "column_name": "Reason" } ] } diff --git a/interface/source_maint/test/srce_set_test.sql b/interface/source_maint/test/srce_set_test.sql index 8bf132c..163c6b7 100644 --- a/interface/source_maint/test/srce_set_test.sql +++ b/interface/source_maint/test/srce_set_test.sql @@ -1,39 +1,4 @@ -SELECT * FROM TPS.SRCE_SET($${ - "name":"dcard", - "source":"client_file", - "loading_function":"csv", - "constraint":[ - "{Trans. Date}", - "{Post Date}" - ], - "schemas":{ - "default":[ - { - "path":"{Trans. Date}", - "type":"date", - "column_name":"Trans. Date" - }, - { - "path":"{Post Date}", - "type":"date", - "column_name":"Post Date" - }, - { - "path":"{Description}", - "type":"text", - "column_name":"Description" - }, - { - "path":"{Amount}", - "type":"numeric", - "column_name":"Amount" - }, - { - "path":"{Category}", - "type":"text", - "column_name":"Category" - } - ], - "version2":[] - } -}$$::JSONB) \ No newline at end of file +SELECT * FROM TPS.SRCE_SET( + $$ + {"name":"dcard","source":"client_file","loading_function":"csv","constraint":["{Trans. Date}","{Post Date}","{Description}"],"schemas":{"default":[{"path":"{Trans. Date}","type":"date","column_name":"Trans. Date"},{"path":"{Post Date}","type":"date","column_name":"Post Date"},{"path":"{Description}","type":"text","column_name":"Description"},{"path":"{Amount}","type":"numeric","column_name":"Amount"},{"path":"{Category}","type":"text","column_name":"Category"}],"mapped":[{"path":"{Trans. Date}","type":"date","column_name":"Trans. Date"},{"path":"{Post Date}","type":"date","column_name":"Post Date"},{"path":"{Description}","type":"text","column_name":"Description"},{"path":"{Amount}","type":"numeric","column_name":"Amount"},{"path":"{Category}","type":"text","column_name":"Category"},{"path":"{party}","type":"text","column_name":"Party"},{"path":"{reason}","type":"text","column_name":"Reason"}]}} + $$::JSONB) \ No newline at end of file