Skip to main content
added 141 characters in body
Source Link

This is a workaround based on the above suggested approach.

 DECLARE
 tables CURSOR FOR SELECT * 
      FROM information_schema.tables 
      whereWHERE table_schema = 'public' 
      ORDER BY "table_name" --presumably 'ASC'ASC
      LIMIT ((selectSELECT count(*)
          fromFROM information_schema.tables
          whereWHERE table_schema = 'public')-1);
          --Because the following prepared string starts with a 'UNION ALL',
          --this completes the query string with a select starting with the last table
          sql_string text := 'SELECT columnsfield1, field7, field8, "source" FROM last_table_in_the_list';' || quote_IDENT((SELECT "table_name" FROM information_schema.tables WHERE table_schema = 'public' ORDER BY "table_name" DESC LIMIT 1));
 
 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;

This is a workaround.

 DECLARE
 tables CURSOR FOR SELECT * 
      FROM information_schema.tables 
      where table_schema = 'public' 
      ORDER BY "table_name" --presumably 'ASC'
      LIMIT ((select count(*)
          from information_schema.tables
          where table_schema = 'public')-1);
          --Because the following prepared string starts with a 'UNION ALL',
          --this completes the query string with a select starting with 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;

This is a workaround based on the above suggested approach.

 DECLARE
 tables CURSOR FOR SELECT * 
      FROM information_schema.tables 
      WHERE table_schema = 'public' 
      ORDER BY "table_name" ASC
      LIMIT ((SELECT count(*)
          FROM information_schema.tables
          WHERE table_schema = 'public')-1);
          --Because the following prepared string starts with a 'UNION ALL',
          --this completes the query string with a select starting with the last table
          sql_string text := 'SELECT field1, field7, field8, "source" FROM ' || quote_IDENT((SELECT "table_name" FROM information_schema.tables WHERE table_schema = 'public' ORDER BY "table_name" DESC LIMIT 1));
 
 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;
added 105 characters in body
Source Link

This is a workaround.

 DECLARE
 tables CURSOR FOR SELECT * 
      FROM information_schema.tables 
      where table_schema = 'public' 
      ORDER BY "table_name" ASC--presumably 'ASC'
      LIMIT 13;((select count(*)
  --Count the number of     from information_schema.tables 
 in the db -      where table_schema = 'public')-1);
           --SinceBecause the executefollowing prepared string beginsstarts with UNION ALL ina the'UNION loopALL', 
           --this initializescompletes itthe query string with a SELECTselect onstarting with 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;

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;

This is a workaround.

 DECLARE
 tables CURSOR FOR SELECT * 
      FROM information_schema.tables 
      where table_schema = 'public' 
      ORDER BY "table_name" --presumably 'ASC'
      LIMIT ((select count(*)
          from information_schema.tables 
          where table_schema = 'public')-1);
          --Because the following prepared string starts with a 'UNION ALL',
          --this completes the query string with a select starting with 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;
deleted 5 characters in body
Source Link

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;

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;

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;
Source Link
Loading