# Problem testing Badge Query from Data Explorer

**URL:** https://meta.discourse.org/t/problem-testing-badge-query-from-data-explorer/118568
**Category:** Data & reporting
**Tags:** sql-triggered-badge
**Created:** [May 24, 2019, 12:14am UTC](https://meta.discourse.org/t/problem-testing-badge-query-from-data-explorer/118568 "2019-05-24T00:14:35Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Mark\_Schmucker](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mark_schmucker/32/124810_2.png) [@Mark\_Schmucker](https://meta.discourse.org/u/Mark_Schmucker)
#### Post date: [May 24, 2019, 12:14am UTC](https://meta.discourse.org/t/problem-testing-badge-query-from-data-explorer/118568/1 "2019-05-24T00:14:35Z")

</div>

Should I be able to run any Badge Query in [Data Explorer](https://meta.discourse.org/t/32566?silent=true)?

I want to create a custom Badge Query using “Appreciated” as a starting point. I type the Appreciated query in [Data Explorer](https://meta.discourse.org/t/32566?silent=true):

```
SELECT p.user_id, current_timestamp AS granted_at
FROM posts AS p
WHERE p.like_count >= 1
    AND (:backfill OR p.user_id IN (:user_ids))
GROUP by p.user_id
HAVING count(*) > 20

```

This gives an error:

`missing value for :backfill`

I vaguely understand that the “:” is a “bind variable” which improves efficiency. I tried removing the bit about backfill but that gives another error.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [May 24, 2019, 12:23am UTC](https://meta.discourse.org/t/problem-testing-badge-query-from-data-explorer/118568/2 "2019-05-24T00:23:05Z")

</div>

You will need to leave out the `AND (:backfill OR p.user_id IN (:user_ids))` condition to run the query in the [Data Explorer](https://meta.discourse.org/t/32566?silent=true). `:backfill` and `:user_ids` both expect parameters to be passed to them.

---

<div class="post-metadata">

### Author: ![Mark\_Schmucker](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mark_schmucker/32/124810_2.png) [@Mark\_Schmucker](https://meta.discourse.org/u/Mark_Schmucker)
#### Post date: [May 24, 2019, 12:27am UTC](https://meta.discourse.org/t/problem-testing-badge-query-from-data-explorer/118568/3 "2019-05-24T00:27:12Z")

</div>

Thanks, it seems to work fine without the AND clause. Can you tell me what the clause does (assuming it gets the parameters passed in), so I can decide whether to keep it?

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [May 24, 2019, 12:46am UTC](https://meta.discourse.org/t/problem-testing-badge-query-from-data-explorer/118568/4 "2019-05-24T00:46:42Z")

</div>

> [@Mark\_Schmucker](#):
>
> Can you tell me what the clause does (assuming it gets the parameters passed in), so I can decide whether to keep it?

If your badge is triggered by a user acting on a post, then you need to include this condition. The best description I’ve seen of how the `:backfill` and `:user_ids` parameters are used in badge queries is in the ‘Triggered badges have 2 extra constraints’ section of [Creating triggered custom badge queries](https://meta.discourse.org/t/triggered-custom-badge-queries/19336).

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [November 10, 2022, 11:00am UTC](https://meta.discourse.org/t/problem-testing-badge-query-from-data-explorer/118568/6 "2022-11-10T11:00:20Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
