# Badge SQL triggered on post content

**URL:** https://meta.discourse.org/t/badge-sql-triggered-on-post-content/394444
**Category:** Data & reporting
**Tags:** sql-triggered-badge
**Created:** [January 27, 2026, 3:25pm UTC](https://meta.discourse.org/t/badge-sql-triggered-on-post-content/394444 "2026-01-27T15:25:37Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Alexander\_Wright](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alexander_wright/32/119518_2.png) [@Alexander\_Wright](https://meta.discourse.org/u/Alexander_Wright)
#### Post date: [January 27, 2026, 3:25pm UTC](https://meta.discourse.org/t/badge-sql-triggered-on-post-content/394444/1 "2026-01-27T15:25:38Z")

</div>

I’m trying to award a badge depending on the content of a post.

For example, If I type ‘Give Me A Badge’ i’m awarded the ‘Demanding’ badge.

My SQL is as follows:

```plaintext
SELECT p.user_id, p.id post_id, p.updated_at granted_at
FROM badge_posts p
WHERE p.raw LIKE '%Give Me A Badge%' 
AND (:backfill OR p.id IN (:post_ids) )
```

With ‘Query targets posts’ and ‘When a user creates or edits a post’.

It’s not, however being triggered. The ’ Badge Query Preview’ shows hits for awards, but the site doesn’t appear to be awarding them.

Help and advice welcome, please.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [February 10, 2026, 2:32pm UTC](https://meta.discourse.org/t/badge-sql-triggered-on-post-content/394444/3 "2026-02-10T14:32:17Z")

</div>

I’m unfortunately not able to reproduce 🤔

That said, I found a couple bugs in `BadgeGranter` that could prevent badges from being granted.

[https://github.com/discourse/discourse/pull/37674](https://github.com/discourse/discourse/pull/37674)

Maybe once it’s merged, you could upgrade and try again?
