Try
IF EXISTS (SELECT * FROM pg_table WHERE tablename=tmp_sources)
THEN
-- table exists
Alternatively, you could try catching the exception in your original
code and handling it.
IF EXISTS (SELECT * FROM tmp_sources) THEN
-- table or view exists
EXCEPTION
Semyon
> How do I check if a table exists, eg. from a PLPGSQL function?
> IF EXISTS (SELECT * FROM tmp_sources) THEN
>
> The function throws an error:
>
> ERROR: relation "tmp_sources" does not exist
>