pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Neill <rjn@richardneill.org>
To: Pavel Stehule <pavel.stehule@gmail.com>
Cc: Richard Neill <rn214@richardneill.org>
Cc: 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 18:35:56 +0000
Message-ID: <4D6FDF8C.1020508@richardneill.org> (raw)
In-Reply-To: <AANLkTi=Yd-BwdsziHE-eyK9M5DvMy+FYqs2YUd9dgxQ3@mail.gmail.com>
References: <201102070601.p1761470087214@wwwmaster.postgresql.org>
	<AANLkTimrzAYxjqFaKRjmVvXiVt_YuAVG54C9EcNW95db@mail.gmail.com>
	<4D6FCBEC.1060709@richardneill.org>
	<AANLkTi=Yd-BwdsziHE-eyK9M5DvMy+FYqs2YUd9dgxQ3@mail.gmail.com>

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



view thread (14+ messages)  latest in thread

Message-ID: <4D6FDF8C.1020508@richardneill.org>
Permalink:  ../4D6FDF8C.1020508@richardneill.org/
Also on:    postgresql.org/message-id/4D6FDF8C.1020508@richardneill.org

 · 

reply

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: rjn@richardneill.org, pavel.stehule@gmail.com, rn214@richardneill.org, robertmhaas@gmail.com, postgresql@richardneill.org
  Subject: Re: BUG #5867: wish: plpgsql print table for debug
  In-Reply-To: <4D6FDF8C.1020508@richardneill.org>
  References: <201102070601.p1761470087214@wwwmaster.postgresql.org> <AANLkTimrzAYxjqFaKRjmVvXiVt_YuAVG54C9EcNW95db@mail.gmail.com> <4D6FCBEC.1060709@richardneill.org> <AANLkTi=Yd-BwdsziHE-eyK9M5DvMy+FYqs2YUd9dgxQ3@mail.gmail.com> <4D6FDF8C.1020508@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