From: Richard Neill <rn214@richardneill.org>
To: Robert Haas <robertmhaas@gmail.com>
Cc: Richard Neill <postgresql@richardneill.org>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #5867: wish: plpgsql print table for debug
Date: Thu, 03 Mar 2011 17:12:12 +0000
Message-ID: <4D6FCBEC.1060709@richardneill.org> (raw)
In-Reply-To: <AANLkTimrzAYxjqFaKRjmVvXiVt_YuAVG54C9EcNW95db@mail.gmail.com>
References: <201102070601.p1761470087214@wwwmaster.postgresql.org>
<AANLkTimrzAYxjqFaKRjmVvXiVt_YuAVG54C9EcNW95db@mail.gmail.com>
>> The following bug has been logged online:
>>
>> Bug reference: 5867
>> Logged by: Richard Neill
>> Email address: postgresql@richardneill.org
>> PostgreSQL version: 9.03
>> Operating system: Linux
>> Description: wish: plpgsql print table for debug
>> Details:
>>
>> When debugging a plpgsql function, it would be really amazingly useful to be
>> able to do a regular psql-style SELECT, and have the result printed to
>> screen.
>>
>> Something like:
>>
>> Raise Notice table 'SELECT .... '
>>
>> and then plpgsql would run the query and dump the result to screen, using
>> its helpful formatting.
>>
>> As far as I can see, this isn't possible (though there are a lot of people
>> searching for how to do it), and the only workaround is to manually handle
>> the looping and formatting, raising lots of individual notices. This makes
>> debugging much harder than it should be.
>
> It wouldn't be too hard to write a loop that runs the select statement
> and does RAISE NOTICE on each row. Getting that into the psql
> formatting would be a little trickier, but I don't see why you
> couldn't write a PL/pgsql function to do it. Then you could just call
> that function and pass it an SQL query every time you want to do this.
>
I'm rather hoping that this would actually be an enhancement to
PL/PGSQL, (or at least an officially documented howto) rather than just
a private debugging function.
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.]
There are a lot of people who would benefit from it, most of whom
(including me) don't really have the expertise to do it well.
Also, there is a lot of value in being able to debug as needed with a
1-line debugging statement, then get back to the problem at hand, rather
than having to break out of the current programming task to write a
debug function :-)
Thanks very much,
Richard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: rn214@richardneill.org, robertmhaas@gmail.com, postgresql@richardneill.org
Subject: Re: BUG #5867: wish: plpgsql print table for debug
In-Reply-To: <4D6FCBEC.1060709@richardneill.org>
References: <201102070601.p1761470087214@wwwmaster.postgresql.org> <AANLkTimrzAYxjqFaKRjmVvXiVt_YuAVG54C9EcNW95db@mail.gmail.com> <4D6FCBEC.1060709@richardneill.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox