Skip to main content
1 of 4

This is a workaround.

 DECLARE
 tables CURSOR FOR SELECT * 
      FROM information_schema.tables 
      where table_schema = 'public' 
      ORDER BY "table_name" ASC 
      LIMIT 13;  --Count the number of tables in the db - 1
           --Since the execute string begins with UNION ALL in the loop, 
           --this initializes it with a SELECT on the last table
      sql_string text := 'SELECT columns FROM last_table_in_the_list';
 
 BEGIN
 
 FOR table_record IN tables LOOP
     sql_string := sql_string || '
         UNION ALL
         SELECT columns FROM ' || quote_IDENT(table_record."table_name");
 END LOOP;
 
 sql_string := sql_string||';';
 RETURN sql_string;
 --EXECUTE sql_string;
 
 END;