in reply to Checking for DB table existence using DBI/DBD

A select is probably the fastest, and is more apt to being optimized away.
dbh->do(q{select 'true' from tests limit 0;})
It should return 0e0 if table exists; or an error if it doesn't.


Evan Carroll
www.EvanCarroll.com

Replies are listed 'Best First'.
Re^2: Checking for DB table existence using DBI/DBD
by pajout (Curate) on Oct 14, 2005 at 07:55 UTC
    Clever idea, but somebody will be confused reading your code - it is not evident, why you selects...

      Yes, but a one-line comment would solve that.

      -xdg

      Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re^2: Checking for DB table existence using DBI/DBD
by danb (Friar) on Oct 14, 2005 at 16:04 UTC

    In Interchange, we use a similar query to get all the column names:

    select * from tests where 6*9=42

    limit 0 isn't portable to all databases, and neither is where false, but the question of life, the universe, and everything is. :)

    --Dan