From 516653afa84ccbf4754fa128ba44d1daabc5ab4d Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Thu, 24 May 2018 13:22:46 -0400 Subject: [PATCH] convert to functino from do block --- interface/source_maint/srce_build_view.sql | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/interface/source_maint/srce_build_view.sql b/interface/source_maint/srce_build_view.sql index 00ed3c3..735b69e 100644 --- a/interface/source_maint/srce_build_view.sql +++ b/interface/source_maint/srce_build_view.sql @@ -1,14 +1,15 @@ -DO +CREATE FUNCTION tps.build_srce_view_sql(_srce text, _schema text) RETURNS TEXT +AS $f$ -DECLARE +DECLARE + --_schema text; _path text[]; - _srce text; + --_srce text; _sql text; - BEGIN - _path:= '{schemas,default}'::text[]; - _srce:= 'dcard'; - + --_schema:= 'default'; + _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||'''' INTO @@ -22,7 +23,9 @@ WHERE GROUP BY srce.srce; +RETURN _sql; RAISE NOTICE '%',_sql; END -$f$; +$f$ +LANGUAGE plpgsql;