Re: Printing command string passed to EXECUTE command in plpgsql (after argument resolution)

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Allan Kamau <kamauallan(at)gmail(dot)com>
Cc: Postgres General Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Printing command string passed to EXECUTE command in plpgsql (after argument resolution)
Date: 2010-10-28 14:40:25
Message-ID: AANLkTi=Ndc40YXohSaNaUj2ra0762VNL=aMT_ecbn1r1@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello

2010/10/28 Allan Kamau <kamauallan(at)gmail(dot)com>:
> I am debugging a plpgsql function which contains a long sql query
> consisting of several parameters which is executed using EXECUTE
> command. I would like to output this command string including the
> actual values of the parameters contained within it so I can obtain
> the actual query and run it directly (manually) in psql (or other
> client such as pgAdmin3). Or at least is possible to output the
> command string as is, followed by the parameter resolution details
> such as $1='2', $2='abc' and so on.
>

if you has a some modern version of PostgreSQL, you can use a
autoexplain contrib module. just do

load 'auto_explain';
set auto_explain.log_min_duration = 0;
set auto_explain.log_nested_statements = true;

select your_function();

look to log

Regards

Pavel Stehule

other solution is just a using a RAISE NOTICE

var := 'SELECT .... ';
RAISE NOTICE '%', var;
EXECUTE var USING ..

Regards

Pavel Stehule

> Allan.
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Leif Biberg Kristensen 2010-10-28 14:47:15 Re: Printing command string passed to EXECUTE command in plpgsql (after argument resolution)
Previous Message Adrian Klaver 2010-10-28 14:37:57 Re: Can't take base back up with Postgres 9.0 on Solaris 10