Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 2884F1337B61 for ; Thu, 3 Mar 2011 14:43:05 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 56246-07 for ; Thu, 3 Mar 2011 18:42:57 +0000 (UTC) X-Greylist: delayed 00:06:24.070547 by SQLgrey-1.7.6 Received: from chocolate.ruo3.org (87-194-171-29.bethere.co.uk [87.194.171.29]) by mail.postgresql.org (Postfix) with ESMTP id 9F2FB1337B54 for ; Thu, 3 Mar 2011 14:42:57 -0400 (AST) Received: from [IPv6:::1] (chocolate.ruo3.org [127.0.0.1]) by chocolate.ruo3.org (Postfix) with ESMTP id 302A26042B; Thu, 3 Mar 2011 18:36:32 +0000 (GMT) Message-ID: <4D6FDF8C.1020508@richardneill.org> Date: Thu, 03 Mar 2011 18:35:56 +0000 From: Richard Neill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101208 Lightning/1.0b2 Thunderbird/3.1.7 MIME-Version: 1.0 To: Pavel Stehule CC: Richard Neill , Robert Haas , Richard Neill , pgsql-bugs@postgresql.org Subject: Re: BUG #5867: wish: plpgsql print table for debug References: <201102070601.p1761470087214@wwwmaster.postgresql.org> <4D6FCBEC.1060709@richardneill.org> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.918 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RDNS_DYNAMIC=0.982 X-Spam-Level: X-Archive-Number: 201103/70 X-Sequence-Number: 29580 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