# "Sorry, An error has occurred" when changing a badge sql trigger to "When a user is edited or created"

**URL:** <https://meta.discourse.org/t/sorry-an-error-has-occurred-when-changing-a-badge-sql-trigger-to-when-a-user-is-edited-or-created/29061>\
**Category:** Bug\
**Created:** [21.Май.2015 07:46:32 UTC](https://meta.discourse.org/t/sorry-an-error-has-occurred-when-changing-a-badge-sql-trigger-to-when-a-user-is-edited-or-created/29061 "2015-05-21T07:46:32Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)\
**Post date:** [21.Май.2015 09:52:27 UTC](https://meta.discourse.org/t/sorry-an-error-has-occurred-when-changing-a-badge-sql-trigger-to-when-a-user-is-edited-or-created/29061/7 "2015-05-21T09:52:27Z")

</div>

Yep… so here’s how it works. When a user updates their profile, your query is run with the `user_ids` parameter set to a comma-separated list of all the users who updated your profile, and you’re supposed to filter your query so that only badges/rows for those users are returned/checked.

Your query is _also_ run daily, with the :user\_ids parameter unset and `:backfill` set to true.

The implementation looks like this:

```sql
SELECT u.id user_id, current_timestamp granted_at
FROM ..., users u
WHERE ...
AND ...
AND (
  u.id IN (:user_ids)
  OR :backfill
)
AND ...

```

---

_[View the full topic](https://meta.discourse.org/t/sorry-an-error-has-occurred-when-changing-a-badge-sql-trigger-to-when-a-user-is-edited-or-created/29061)._
