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

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Richard Neill <rjn(at)richardneill(dot)org>
Cc: Richard Neill <rn214(at)richardneill(dot)org>, Richard Neill <postgresql(at)richardneill(dot)org>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #5867: wish: plpgsql print table for debug
Date: 2011-03-03 18:45:21
Message-ID: AANLkTi=Tn9131=2cc2QwmSFjiSHTmFbCdAoCU6Y0H6Yf@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Thu, Mar 3, 2011 at 1:37 PM, Richard Neill <rjn(at)richardneill(dot)org> wrote:
>
>> Sure it does.  You can pass the tuple to RAISE NOTICE easily enough.
>> It won't have all the same bells and whistles psql would supply, but
>> it prints out well enough for debugging.  Or at least it's never
>> bothered me.
>
> Sorry if I'm being dense, but I can't see how you can pass a tuple; I think
> raise-notice only lets you pass individual strings/integers. But I don't
> think we can pass all of them without specifying in advance how many there
> are....

Pavel had it almost right. Here's a version that works for me.

CREATE FUNCTION debug_query(qry text) RETURNS void
LANGUAGE plpgsql
AS $$
declare
r record;
begin
for r in execute qry loop
raise notice '%', r;
end loop;
end
$$;

And here it is doing its thing:

rhaas=# select debug_query('SELECT * FROM foo');
NOTICE: (1,Richard)
NOTICE: (2,Robert)
NOTICE: (3,Tom)
debug_query
-------------

(1 row)

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Richard Neill 2011-03-03 18:48:11 Re: BUG #5867: wish: plpgsql print table for debug
Previous Message Richard Neill 2011-03-03 18:37:33 Re: BUG #5867: wish: plpgsql print table for debug