ActiveSupport helpers implemented in pl/pgsql