Debug and TEMP TABLE output:

Sometimes you have the need to analyze the data of a TEMP TABLE. This is (as far as I know) not as easy with PostgreSQL than with SQL Server.


Here are two possible solutions with RAISE INFO. The idea is always to go through the table with LOOP and output the single columns.

 

Solution 1:

    DECLARE items record;
    Begin
    FOR items IN SELECT * FROM myTable LOOP
        RAISE INFO 'col1: %, col2: %', items.myName, items.myAge;
    END LOOP;
    End;

 

Solution 2:

   DECLARE t_debug int := 1;
   DECLARE t_record RECORD;
   Begin
   IF t_debug > 0 THEN
       FOR t_record IN SELECT * FROM myTable LOOP
         RAISE INFO 'Row in myTable: %', t_record::text;
      END LOOP;
   END IF;
   End;

 

Print a single value:

raise notice 'RID value: %', (__myvalue::text);