Creating a table if it doesn't exist (old versions of PostgreSQL)
The actual solution very much depends on your exact situation.  If you can use a pl/pgsql function, you can check first for the existence of the table:

IF NOT EXISTS (SELECT 1 FROM pg_class WHERE relname = 'my_table')
THEN
    CREATE TEMPORARY TABLE my_table ...
END IF;


You could also try to match the schema name (which will be something like pg_temp*) by joining the pg_namespace table to pg_class.  Or use the pg_tables view, which can be a bit easier.