Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: DBI: checking if a table exists in a cross-DB manner?

by htoug (Deacon)
on Dec 03, 2004 at 11:29 UTC ( #412089=note: print w/replies, xml ) Need Help??

in reply to DBI: checking if a table exists in a cross-DB manner?

You should use the $dbh->table_info(...) method.

It will return a statement handle, that iterates the table(s) you define, thus alloowing easy check whether a table exists.

Your call would be something like

$sth=$dbh->table_info("", $schema, $table_name, "TABLE"); if ($sth->fetch) { # table exists } else { # doesn't }
This will work on all DBD's (as soon as the authors have implemented the table_info method - most have). If yours doesn't work, then please contact your DBD-author and help him get it done.

Replies are listed 'Best First'.
Re^2: DBI: checking if a table exists in a cross-DB manner?
by Anonymous Monk on Aug 25, 2016 at 14:06 UTC
    Thank u, is very simple and works!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://412089]
LanX is sure Louvre is going to move to Glasgow after brexit
[ambrus]: marto: http://www. irregularwebcomic. net/3498.html and http://www. irregularwebcomic. net/3549.html
[ambrus]: the annotation mentions Brisbane as even worse, and I add Debrecen
[marto]: :)
[ambrus]: robby: dunno, I would like to visit London some time, although there are other places I'd like to visit more
[marto]: "Okay, sure, there are in fact museums and art galleries and other culturally enlightened things to do in Glasgow, but that wouldn't have made a funny comic"

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2017-12-15 11:07 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (431 votes). Check out past polls.