I encountered the following problem in several of the development projects I have been working on and haven't found a solution yet.
For our application we need a database backend (at the moment postgreSQL) and we have this sql script which will create all the tables for us and populates them with data. Each developer has its on db on his machine. The very first time the build is run on the machine we just create the tables. Cool. But in the case a developer wants to recreate already existing tables we need drop table statemments in the script. So depending on the situation we either would like to drop tables first or in the other case jsut create them.
We need a conditional table drop. I know I can query pg_tables to find if a table exists:
select * from pg_tables where tablename = 'xyz'
But how to I combine this with a drop statement.