make view creationg script use allj

This commit is contained in:
Paul Trowbridge 2018-05-25 10:25:09 -04:00
parent 39820d6051
commit c6554831a1
3 changed files with 49 additions and 84 deletions

View File

@ -224,7 +224,7 @@ LANGUAGE plpgsql;
-----generate sql to create select based on schema -----generate sql to create select based on schema
DROP FUNCTION IF EXISTS tps.build_srce_view_sql(text, text); 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 AS
$f$ $f$
DECLARE DECLARE
@ -237,7 +237,7 @@ BEGIN
_path:= ARRAY['schemas',_schema]::text[]; _path:= ARRAY['schemas',_schema]::text[];
--_srce:= 'dcard'; --_srce:= 'dcard';
SELECT 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 INTO
_sql _sql
FROM FROM

View File

@ -1,75 +1,75 @@
{ {
"name":"dcard", "name": "dcard",
"source":"client_file", "source": "client_file",
"loading_function":"csv", "loading_function": "csv",
"constraint":[ "constraint": [
"{Trans. Date}", "{Trans. Date}",
"{Post Date}", "{Post Date}",
"{Description}" "{Description}"
], ],
"schemas":{ "schemas": {
"default":[ "default": [
{ {
"path":"{Trans. Date}", "path": "{Trans. Date}",
"type":"date", "type": "date",
"column_name":"Trans. Date" "column_name": "Trans. Date"
}, },
{ {
"path":"{Post Date}", "path": "{Post Date}",
"type":"date", "type": "date",
"column_name":"Post Date" "column_name": "Post Date"
}, },
{ {
"path":"{Description}", "path": "{Description}",
"type":"text", "type": "text",
"column_name":"Description" "column_name": "Description"
}, },
{ {
"path":"{Amount}", "path": "{Amount}",
"type":"numeric", "type": "numeric",
"column_name":"Amount" "column_name": "Amount"
}, },
{ {
"path":"{Category}", "path": "{Category}",
"type":"text", "type": "text",
"column_name":"Category" "column_name": "Category"
} }
], ],
"mapped":[ "mapped": [
{ {
"path":"{Trans. Date}", "path": "{Trans. Date}",
"type":"date", "type": "date",
"column_name":"Trans. Date" "column_name": "Trans. Date"
}, },
{ {
"path":"{Post Date}", "path": "{Post Date}",
"type":"date", "type": "date",
"column_name":"Post Date" "column_name": "Post Date"
}, },
{ {
"path":"{Description}", "path": "{Description}",
"type":"text", "type": "text",
"column_name":"Description" "column_name": "Description"
}, },
{ {
"path":"{Amount}", "path": "{Amount}",
"type":"numeric", "type": "numeric",
"column_name":"Amount" "column_name": "Amount"
}, },
{ {
"path":"{Category}", "path": "{Category}",
"type":"text", "type": "text",
"column_name":"Category" "column_name": "Category"
}, },
{ {
"path":"{party}", "path": "{party}",
"type":"text", "type": "text",
"column_name":"Party" "column_name": "Party"
}, },
{ {
"path":"{reason}", "path": "{reason}",
"type":"text", "type": "text",
"column_name":"Reason" "column_name": "Reason"
} }
] ]
} }

View File

@ -1,39 +1,4 @@
SELECT * FROM TPS.SRCE_SET($${ SELECT * FROM TPS.SRCE_SET(
"name":"dcard", $$
"source":"client_file", {"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"}]}}
"loading_function":"csv", $$::JSONB)
"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)