in reply to if table exists (DBI)

MySQL allows for this logic built into its statements, for example:
CREATE TABLE IF NOT EXISTS my_table ( foo INT, bar VARCHAR(25) );
AFAIK, this is only valid for MySQL, and not other SQL variants. A quick way to get all of your tables is to send a SHOW TABLES query. It will return a list of all of the tables. Oops, looks like you knew that and wanted to avoid it.

blokhead

Replies are listed 'Best First'.
Re^2: if table exists (DBI)
by erix (Prior) on Apr 26, 2013 at 16:47 UTC

    this is only valid for MySQL,

    PostgreSQL has IF [NOT] EXISTS for many objects; also for TABLE:

    $ psql psql (9.2.4) Type "help" for help. # CREATE TABLE IF NOT EXISTS my_table (foo INT, bar VARCHAR (25) ); CREATE TABLE # \d my_table Table "public.my_table" Column | Type | Modifiers --------+-----------------------+----------- foo | integer | bar | character varying(25) |

    ( So there is also: DROP <object> IF EXISTS ... ;

    # drop table if exists my_table; -- exists DROP TABLE # drop table if exists my_table; -- no table is no problem: DROP TABLE #

    )

    Of course postgres can also ROLLBACK on DDL statements. Not many DBMS's implement *that*, I think.