Thread: How to 'print a table' in the middle of a plpgsql function
I am deep into debugging some pretty extensive plpgsql and it would be nice sometimes if I could somehow output the contentof a table to the psql console at a particular point in a function. For example, I am executing a select that is not returning the expected row. So I am wondering, what exactly was in thetable at the time the query was performed. Of course, I could just write a loop prior to my query with a bunch of raise notice statements, but I'll get a stack tracefor each one. So that won't be pretty. Suggestions? Thx. - Leon
On 1/29/2011 12:59 AM, Leon Starr wrote: > I am deep into debugging some pretty extensive plpgsql and it would be nice sometimes if I could somehow output the contentof a table to the psql console at a particular point in a function. > > For example, I am executing a select that is not returning the expected row. So I am wondering, what exactly was in thetable at the time the query was performed. > > Of course, I could just write a loop prior to my query with a bunch of raise notice statements, but I'll get a stack tracefor each one. So that won't be pretty. > > Suggestions? Thx. Raise notice is PLPGSQL equivalent of DBMS_OUTPUT.PUT_LINE. -- Mladen Gogala Sr. Oracle DBA 1500 Broadway New York, NY 10036 (212) 329-5251 www.vmsinfo.com
You can use RAISE INFO instead (it doesn't print the stack)
http://www.postgresql.org/docs/7.4/static/plpgsql-errors-and-messages.html
There is also a pgAdmin Debugger
http://www.pgadmin.org/docs/1.8/debugger.html
There is also a pgAdmin Debugger
http://www.pgadmin.org/docs/1.8/debugger.html
On Sun, Jan 30, 2011 at 1:19 AM, Mladen Gogala <mladen.gogala@vmsinfo.com> wrote:
On 1/29/2011 12:59 AM, Leon Starr wrote:Raise notice is PLPGSQL equivalent of DBMS_OUTPUT.PUT_LINE.I am deep into debugging some pretty extensive plpgsql and it would be nice sometimes if I could somehow output the content of a table to the psql console at a particular point in a function.
For example, I am executing a select that is not returning the expected row. So I am wondering, what exactly was in the table at the time the query was performed.
Of course, I could just write a loop prior to my query with a bunch of raise notice statements, but I'll get a stack trace for each one. So that won't be pretty.
Suggestions? Thx.
--
Mladen Gogala
Sr. Oracle DBA
1500 Broadway
New York, NY 10036
(212) 329-5251
www.vmsinfo.com
--
Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice
Thanks, I didn't know that about RAISE INFO. I checked your link for my version 8.4, (which I had already read about a dozen times) but I can't find any place where the INFO format is documented. I will give it a try!
Not sure what is involved getting the debugger to run on mac os x, but I will check it out.
- Leon
On Jan 29, 2011, at 7:55 PM, ashima athri wrote:
You can use RAISE INFO instead (it doesn't print the stack)http://www.postgresql.org/docs/7.4/static/plpgsql-errors-and-messages.html
There is also a pgAdmin Debugger
http://www.pgadmin.org/docs/1.8/debugger.htmlOn Sun, Jan 30, 2011 at 1:19 AM, Mladen Gogala <mladen.gogala@vmsinfo.com> wrote:On 1/29/2011 12:59 AM, Leon Starr wrote:I am deep into debugging some pretty extensive plpgsql and it would be nice sometimes if I could somehow output the content of a table to the psql console at a particular point in a function.
For example, I am executing a select that is not returning the expected row. So I am wondering, what exactly was in the table at the time the query was performed.
Of course, I could just write a loop prior to my query with a bunch of raise notice statements, but I'll get a stack trace for each one. So that won't be pretty.
Suggestions? Thx.
--
Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice
Using Postgresql 8.4, I find that RAISE INFO does in fact print the stack to the psql console, just like
RAISE NOTICE and RAISE EXCEPTION.
On Jan 29, 2011, at 7:55 PM, ashima athri wrote:
You can use RAISE INFO instead (it doesn't print the stack)http://www.postgresql.org/docs/7.4/static/plpgsql-errors-and-messages.html
There is also a pgAdmin Debugger
http://www.pgadmin.org/docs/1.8/debugger.htmlOn Sun, Jan 30, 2011 at 1:19 AM, Mladen Gogala <mladen.gogala@vmsinfo.com> wrote:On 1/29/2011 12:59 AM, Leon Starr wrote:Raise notice is PLPGSQL equivalent of DBMS_OUTPUT.PUT_LINE.I am deep into debugging some pretty extensive plpgsql and it would be nice sometimes if I could somehow output the content of a table to the psql console at a particular point in a function.
For example, I am executing a select that is not returning the expected row. So I am wondering, what exactly was in the table at the time the query was performed.
Of course, I could just write a loop prior to my query with a bunch of raise notice statements, but I'll get a stack trace for each one. So that won't be pretty.
Suggestions? Thx.
--
Mladen Gogala
Sr. Oracle DBA
1500 Broadway
New York, NY 10036
(212) 329-5251
www.vmsinfo.com
--
Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice