Search code examples
debuggingselectrowpostgresql-9.2stringification

Postgres 9.2 select star into an array


I want to do something like this inside a stored procedure so I can see the result of an insert statement for debugging:

thing := array_to_string(ARRAY(select * from some_table limit 1 ));
raise info 'insert result: %',thing;

Where all the columns of some_table get concatenated into an array

Is there a way to do this?


Solution

  • Arrays are of uniform type. You can't have an array where different entries have different data types.

    What you appear to want is an anonymous row (record).

    DECLARE
        debug_row record;
    BEGIN
        SELECT * FROM some_table LIMIT 1 INTO debug_row;
        RAISE INFO 'insert result: %',debug_row;
    

    Note that this only works for a single row result. For multiple rows you can call the query as the input for a loop and iterate over the result. There are examples in the PL/PgSQL documentation.