Saving the output of a dynamic query that uses prepare statement into a table
问题 In continuation to a previous case (a solution by @Erwin Brandstetter), in which a dynamic SELECT query that uses a 'prepare' statement was created and then was executed by calling it, as below: --the function for making the prepare statement: CREATE OR REPLACE FUNCTION f_prep_query (_tbl regclass, _prefix text) RETURNS void AS $func$ DECLARE _prep_qry text := ( SELECT 'PREPARE stmt_dyn AS SELECT ' || string_agg(quote_ident(attname), ',' ORDER BY attname) || ' FROM ' || _tbl FROM pg_attribute