# Get list of topics pinned globally

**URL:** https://meta.discourse.org/t/get-list-of-topics-pinned-globally/68972
**Category:** Data & reporting
**Tags:** sql-query
**Created:** [29.Август.2017 07:41:55 UTC](https://meta.discourse.org/t/get-list-of-topics-pinned-globally/68972 "2017-08-29T07:41:55Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![adopilot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/adopilot/32/105040_2.png) [@adopilot](https://meta.discourse.org/u/adopilot)
#### Post date: [29.Август.2017 07:41:55 UTC](https://meta.discourse.org/t/get-list-of-topics-pinned-globally/68972/1 "2017-08-29T07:41:55Z")

</div>

Is there a way to get list of topics which are pinned globally.

In advanced search there is “are pinned” but it does list all pined topics.

 ![image](https://global.discourse-cdn.com/meta/original/3X/e/d/ed7636c52941021142460bd07a95a1fc138d6f03.png)

We wold like to find globally pined topics so we can clear our latest list.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [29.Август.2017 11:37:34 UTC](https://meta.discourse.org/t/get-list-of-topics-pinned-globally/68972/2 "2017-08-29T11:37:34Z")

</div>

The usual way is to view the site in incognito mode in your browser.

---

<div class="post-metadata">

### Author: ![adopilot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/adopilot/32/105040_2.png) [@adopilot](https://meta.discourse.org/u/adopilot)
#### Post date: [29.Август.2017 11:57:49 UTC](https://meta.discourse.org/t/get-list-of-topics-pinned-globally/68972/3 "2017-08-29T11:57:49Z")

</div>

We unfortunately require logins to view any content .  
I need then dummy account to reuse.

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [29.Август.2017 12:18:52 UTC](https://meta.discourse.org/t/get-list-of-topics-pinned-globally/68972/4 "2017-08-29T12:18:52Z")

</div>

If you have [Data Explorer](https://meta.discourse.org/t/32566?silent=true) Plugin installed, this should do it.  
[pinned-topics.dcquery.json](https://global.discourse-cdn.com/meta/original/3X/7/5/75cf2cf238a2ab190b1fb75babc7930e28d31f27.json) (213 Bytes)

---

<div class="post-metadata">

### Author: ![adopilot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/adopilot/32/105040_2.png) [@adopilot](https://meta.discourse.org/u/adopilot)
#### Post date: [29.Август.2017 12:27:04 UTC](https://meta.discourse.org/t/get-list-of-topics-pinned-globally/68972/5 "2017-08-29T12:27:04Z")

</div>

Thanx for tip here is corrected version for others.  
Added pinned\_globally=TRUE in where clue

`SELECT id, title, user, category_id ,pinned_globally FROM topics WHERE pinned_at IS NOT NULL and pinned_globally=TRUE`

`{"query":{"id":12,"sql":"SELECT id, title, user, category_id ,pinned_globally FROM topics WHERE pinned_at IS NOT NULL and pinned_globally=TRUE","name":"Pinned Topics","description":"Enter a description here","param_info":[]}}`

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [18.Февраль.2019 04:29:01 UTC](https://meta.discourse.org/t/get-list-of-topics-pinned-globally/68972/6 "2019-02-18T04:29:01Z")

</div>

Note `in:pinned` should find all pinned topics be they globally or locally pinned.

---

<div class="post-metadata">

### Author: ![Bathinda](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bathinda/32/135888_2.png) [@Bathinda](https://meta.discourse.org/u/Bathinda)
#### Post date: [05.Март.2020 03:46:10 UTC](https://meta.discourse.org/t/get-list-of-topics-pinned-globally/68972/7 "2020-03-05T03:46:10Z")

</div>

При запуске возникает следующая ошибка:

```plaintext
PG::SyntaxError: ERROR: синтаксическая ошибка вблизи "{"
LINE 9: {"query":{"id":12,"sql":"SELECT id, title, user, category_id...
        ^

```

---

<div class="post-metadata">

### Author: ![nathank](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nathank/32/290039_2.png) [@nathank](https://meta.discourse.org/u/nathank)
#### Post date: [20.Январь.2022 10:08:34 UTC](https://meta.discourse.org/t/get-list-of-topics-pinned-globally/68972/8 "2022-01-20T10:08:34Z")

</div>

Вот обновленный запрос [Data Explorer](https://meta.discourse.org/t/32566?silent=true), который возвращает более аккуратный список всех закрепленных постов по категориям, при этом глобально закрепленные темы отображаются вверху:

```plaintext
SELECT pinned_globally, TO_CHAR(pinned_until,'DD/MM/YYYY') as pinned_till, id as topic_id, user_id, category_id 
FROM topics 
WHERE deleted_at IS NULL
AND pinned_at IS NOT NULL
AND (pinned_until IS NULL OR pinned_until > CURRENT_TIMESTAMP)
ORDER BY pinned_globally desc, category_id

```
