From: Heiko Irrgang <irrgang@SC-Networks.de>
To: pgsql-general@postgresql.org
Subject: Re: Explain
Date: Fri, 5 Jan 2001 11:25:12 +0200
Message-ID: <a04320404b67b41bbd16c@[192.168.66.11]> (raw)
In-Reply-To: <0101050121130A.01054@jdavis>
References: <0101050121130A.01054@jdavis>
>How can I conveniently handle output from an EXPLAIN query inside an
>application? It appears to just immediately send the output to the stdout of
>whatever program uses it. Is there a way to get the output inside a program,
>with libpq or otherwise? I would actually like to be able to get the output in
>a PHP script, but getting it in any application would be nice.
AFAIK it dont works directly, but you can do the following:
<?php
$f=popen("psql -U username -c 'explain select * from table' -d dbname
2>/dev/stdout","r");
while($nextline=fgets($f,4096)) {
echo($nextline."<br>");
}
pclose($f);
?>
this would dump the explain-result as you get it in psql as html-text.
with popen("command","r") you open a stream to the command and
because psql seems to send
the result of explain to stderr you have to redirect it to stdout
(2>/dev/stdout)
then you can handle the filedescriptor delivered by popen() as a normal file
with fgets(), but you have to close it with pclose() not fclose().
this works exactly the same within a c program but i dont know much
about programming postgres in c. it may be possible to have the
same result directly with libpq, but for php this seems to be
the only way to do this.
--
SC-Networks www: www.SC-Networks.de
Web Design, Netzwerke,
3D Animation und Multimedia
Heiko Irrgang Tel.: 08856/9392-00
Im Thal 2 Fax: 08856/9392-01
82377 Penzberg Mail: Irrgang@SC-Networks.de
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 using the --to and --cc options:
reply via email
To: pgsql-general@postgresql.org
Cc: irrgang@SC-Networks.de
Subject: Re: Explain
In-Reply-To: <a04320404b67b41bbd16c@[192.168.66.11]>
* 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