diff --git a/srce.pgsql b/srce.pgsql index cec92cd..0edffb9 100644 --- a/srce.pgsql +++ b/srce.pgsql @@ -1,3 +1,4 @@ +/* SELECT jsonb_pretty( $$ @@ -39,4 +40,35 @@ $$ } } $$::jsonb -) \ No newline at end of file +) +*/ + +DO $$ + +declare _t text; + +begin + + SELECT + string_agg(quote_ident(prs.key)||' '||prs.type,',') + INTO + _t + FROM + TPS.srce + --unwrap the schema definition array + LEFT JOIN LATERAL jsonb_populate_recordset(null::tps.srce_defn_schema, defn->'schema') prs ON TRUE + GROUP BY + srce; + + raise notice '%', _t; + _t := format('CREATE TEMP TABLE csv_i (%s)', _t); + raise notice '%', _t; + + DROP TABLE IF EXISTS csv_i; + + EXECUTE _t; + +end +$$; + +SELECT * FROM csv_i; \ No newline at end of file