On Thu, 30 Aug 2001, Jeff Boes wrote:

> Does anyone have a slick way to capture the output of an EXPLAIN command
> issued via DBI (specifically, DBD::Pg)?
> 
> I'm attempting to extend a query generator so that it can intelligently
> select columns to build a WHERE clause based on a record (hashref)
> received.  What I want to do is something like this:
> 
> foreach (@column_names) {
>   $dbh->do(qq!EXPLAIN SELECT * FROM emp WHERE $_ = 0!);
>   last if (...it's an index scan...);
> }
> 
> The EXPLAIN SELECT statement will produce, under DBD::Pg, output that
> looks like
> 
>     NOTICE:  QUERY PLAN:
>  
>     Index Scan using emp_pkey on emp  (cost=0.00..6.07 rows=5 width=238)
> 
> but it does so to STDOUT, not as the return value of the 'do' method.

Not yet. Patches are welcome. Maybe if I get a free hour or two, I could
do it.

Here's my idea for implementation of this: libpq has a 'notice processor'
concept, a function that will be called when a NOTICE/WARNING/ERROR is
received from backend. DBD::Pg could conceivably allow for a perl function
to be used as notice processor, providing some glue to make it
work.

Shouldn't take more than a few hours, maybe next week.
someone pays me for it :)

My tiny annoyance with DBI is (or maybe I don't understand the way DBI
works) is that the only way I can add driver-specific functions to DBI
handle is by using $dbh->func('funcname',args), which is pretty ugly. Is
there a better way to be able to write directly $dbh->funcname(args)?



Reply via email to