# Badge for reading a topic?

**URL:** https://meta.discourse.org/t/badge-for-reading-a-topic/281534
**Category:** Data & reporting
**Tags:** sql-triggered-badge
**Created:** [October 8, 2023, 1:23pm UTC](https://meta.discourse.org/t/badge-for-reading-a-topic/281534 "2023-10-08T13:23:15Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![barto\_95](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/barto_95/32/199996_2.png) [@barto\_95](https://meta.discourse.org/u/barto_95)
#### Post date: [October 8, 2023, 1:23pm UTC](https://meta.discourse.org/t/badge-for-reading-a-topic/281534/1 "2023-10-08T13:23:15Z")

</div>

It’s possible to add a badge if user read the specific topic/subject of forum ? and not just opened the topic but he read ~5minutes to be sure the user read the info ?

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [October 8, 2023, 8:09pm UTC](https://meta.discourse.org/t/badge-for-reading-a-topic/281534/2 "2023-10-08T20:09:11Z")

</div>

I think this should be possible with something like:

```sql
SELECT user_id, CURRENT_TIMESTAMP AS granted_at
FROM topic_users
WHERE topic_id = 281534
  AND total_msecs_viewed/60000 >= 5 -- min number of minutes viewed

```

---

<div class="post-metadata">

### Author: ![barto\_95](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/barto_95/32/199996_2.png) [@barto\_95](https://meta.discourse.org/u/barto_95)
#### Post date: [October 9, 2023, 8:49am UTC](https://meta.discourse.org/t/badge-for-reading-a-topic/281534/3 "2023-10-09T08:49:41Z")

</div>

I test and received this error:

`Error : Contract violation: Query targets posts, but does not return a 'post_id' column`

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [October 9, 2023, 8:57am UTC](https://meta.discourse.org/t/badge-for-reading-a-topic/281534/4 "2023-10-09T08:57:45Z")

</div>

I think that’s because you’ve ticked the ‘Query targets posts’ box. If you set it up to more like this it should work fine:

 ![badge options](https://global.discourse-cdn.com/meta/original/4X/4/c/5/4c5b5cd3464782528b4355f0ce6c3e8d3c97bef9.png)

---

<div class="post-metadata">

### Author: ![barto\_95](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/barto_95/32/199996_2.png) [@barto\_95](https://meta.discourse.org/u/barto_95)
#### Post date: [October 9, 2023, 9:21am UTC](https://meta.discourse.org/t/badge-for-reading-a-topic/281534/5 "2023-10-09T09:21:30Z")

</div>

> [@JammyDodger](#):
>
> ```plaintext
> SELECT user_id, CURRENT_TIMESTAMP AS granted_at
> FROM topic_users
> WHERE topic_id = 281534
> AND total_msecs_viewed/60000 >= 5 -- min number of minutes viewed
> 
> ```

Ok thank’s no error now

what do you recommend as a trigger ?

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [October 9, 2023, 9:58am UTC](https://meta.discourse.org/t/badge-for-reading-a-topic/281534/6 "2023-10-09T09:58:19Z")

</div>

I think it would have to be Update Daily. I don’t think any of the other triggers would catch a change in the `topic_users` read time stat.

---

<div class="post-metadata">

### Author: ![barto\_95](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/barto_95/32/199996_2.png) [@barto\_95](https://meta.discourse.org/u/barto_95)
#### Post date: [October 9, 2023, 10:01am UTC](https://meta.discourse.org/t/badge-for-reading-a-topic/281534/7 "2023-10-09T10:01:01Z")

</div>

Ok I configured this first for test

this happens every 22 hours it seems to me regarding the assignment of badges

---

<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 8, 2023, 10:01am UTC](https://meta.discourse.org/t/badge-for-reading-a-topic/281534/8 "2023-11-08T10:01:17Z")

</div>

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