convert to functino from do block
This commit is contained in:
parent
80406a2dc6
commit
516653afa8
@ -1,14 +1,15 @@
|
|||||||
DO
|
CREATE FUNCTION tps.build_srce_view_sql(_srce text, _schema text) RETURNS TEXT
|
||||||
|
AS
|
||||||
$f$
|
$f$
|
||||||
DECLARE
|
DECLARE
|
||||||
|
--_schema text;
|
||||||
_path text[];
|
_path text[];
|
||||||
_srce text;
|
--_srce text;
|
||||||
_sql text;
|
_sql text;
|
||||||
|
|
||||||
BEGIN
|
BEGIN
|
||||||
_path:= '{schemas,default}'::text[];
|
--_schema:= 'default';
|
||||||
_srce:= 'dcard';
|
_path:= ARRAY['schemas',_schema]::text[];
|
||||||
|
--_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('(rec#>>'''||r.PATH::text||''')::'||r.type||' AS "'||r.column_name||'"',', ')||' FROM tps.trans WHERE srce = '''||_srce||''''
|
||||||
INTO
|
INTO
|
||||||
@ -22,7 +23,9 @@ WHERE
|
|||||||
GROUP BY
|
GROUP BY
|
||||||
srce.srce;
|
srce.srce;
|
||||||
|
|
||||||
|
RETURN _sql;
|
||||||
RAISE NOTICE '%',_sql;
|
RAISE NOTICE '%',_sql;
|
||||||
|
|
||||||
END
|
END
|
||||||
$f$;
|
$f$
|
||||||
|
LANGUAGE plpgsql;
|
||||||
|
Loading…
Reference in New Issue
Block a user