|laziness, impatience, and hubris|
DBI: checking if a table exists in a cross-DB manner?by radiantmatrix (Parson)
|on Dec 02, 2004 at 19:54 UTC||Need Help??|
radiantmatrix has asked for the
wisdom of the Perl Monks concerning the following question:
I am aware that many RDBMS packages provide a mechanism to check for the existance of a table via SQL. I've also read if table exists (DBI) on the subject, but it does not provide an answer for me. I need to examine whether or not a table exists in a way that is portable to all (or at least most) DBI-able RDBMS.
At least, that's what I think I need to do... My logic looks like this in psuedo-code:
The reason for this is that I need to purge all records from a table, and then insert data from a flat file into a cleanly-created table. When the files change, %schema changes as well. DELETE FROM $table_name is too slow (approx 1.5M records per table).
This works, but assumes that any error means the table just didn't exist:
That's a Bad Thing™, IMO, partly because I'd like to provide the option of prompting the user with something like "This table exists, are you sure you wish to drop it?" when the table is already there. Any ideas on a better way to approach this challenge, and one that will work with pretty much any DB supported by DBI?