--
-- table_exists/1
--
create or replace function table_exists(
  character varying
) returns bool as $$

declare
        table_exists__table_name             alias for $1;  
begin

        return count(*) > 0
          from pg_class 
         where relname = lower(table_exists__table_name);
 
end;$$ language plpgsql;