Re: BUG #5867: wish: plpgsql print table for debug

Поиск
Список
Период
Сортировка
От Richard Neill
Тема Re: BUG #5867: wish: plpgsql print table for debug
Дата
Msg-id 4D6FDF8C.1020508@richardneill.org
обсуждение исходный текст
Ответ на Re: BUG #5867: wish: plpgsql print table for debug  (Pavel Stehule <pavel.stehule@gmail.com>)
Список pgsql-bugs
Dear Pavel,

Thanks for your help.

>> Do you not think it would be really amazingly useful? After all, in C, the
>> single most useful debugging tool is "fprintf(stderr,...)", and yet
>> postgresql doesn't have an equivalent that can operate on the most common
>> data format. [I'm stretching the analogy a bit here, but it seems to me that
>> a multi-row table is to postgresql as int is to C.]
>
> it's nonsense - PL/pgSQL is procedural language - so there are same -
> similar types like C

Sorry - I perhaps over-stretched the analogy. What I meant was that, at
least apparently, SQL "types"  include anything that can result from an
SQL statement, including an individual "record" or an entire temporary
table. I know that strictly speaking this isn't true, but it seems to me
that one should be able to do:
   RAISE NOTICE (SELECT ....)


> CREATE OR REPLACE FUNCTION debug_query(text)
> RETURNS void AS $$
> DECLARE r record;
> BEGIN
>    FOR r IN EXECUTE $1 LOOP
>      RAISE NOTICE r;
>    END;
> END;
> $$ LANGUAGE plpgsql;

Thanks for your help - but I'm afraid this doesn't actually work. psql
rejects the line "RAISE NOTICE r;"

Raise notice expects a format string and some variables, very similar to
printf(). This means that we'd have to write something like:
    RAISE NOTICE ('first %, second %, third %', col1, col2, col3;
except that our debug_query function doesn't know in advance how many
columns there are, (or the types and their names).


Richard

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Robert Haas
Дата:
Сообщение: Re: BUG #5867: wish: plpgsql print table for debug
Следующее
От: Richard Neill
Дата:
Сообщение: Re: BUG #5867: wish: plpgsql print table for debug