PostgreSQL create table if not exists
In a MySQL script you can write: CREATE TABLE IF NOT EXISTS foo ...; ... other stuff ... and then you can run the script many times without re-creating the table. How do you do this in PostgreSQL? This feature has been implemented in Postgres 9.1 : CREATE TABLE IF NOT EXISTS myschema.mytable (i integer); For older versions , here is a function to work around it: CREATE OR REPLACE FUNCTION create_mytable () RETURNS void AS $func$ BEGIN IF EXISTS (SELECT 1 FROM pg_catalog.pg_tables WHERE schemaname = 'myschema' AND tablename = 'mytable') THEN RAISE NOTICE 'Table myschema.mytable already exists.'