--
-- rule_exists/2
--
create or replace function rule_exists(
  character varying,
  character varying
) returns bool as $$

declare
        rule_name       alias for $1;
        table_name      alias for $2;
begin
        return count(*) = 1
          from pg_rules
         where tablename::varchar = lower(table_name)
           and rulename::varchar = lower(rule_name);

end;$$ language plpgsql;