# Top 50 Largest Uploads broken script

**URL:** https://meta.discourse.org/t/top-50-largest-uploads-broken-script/284017
**Category:** Bug
**Tags:** data-explorer
**Created:** [October 31, 2023, 2:58pm UTC](https://meta.discourse.org/t/top-50-largest-uploads-broken-script/284017 "2023-10-31T14:58:42Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Ivan\_Rapekas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ivan_rapekas/32/248924_2.png) [@Ivan\_Rapekas](https://meta.discourse.org/u/Ivan_Rapekas)
#### Post date: [October 31, 2023, 2:58pm UTC](https://meta.discourse.org/t/top-50-largest-uploads-broken-script/284017/1 "2023-10-31T14:58:42Z")

</div>

Sometimes I use explorer script to find large uploads.

When I try to run the query

```sql
SELECT posts.id AS post_id,
    uploads.original_filename,
    ROUND(uploads.filesize / 1000000.0, 2) AS size_in_mb,
    uploads.extension,
    uploads.created_at,
    uploads.url
FROM post_uploads
JOIN uploads ON uploads.id = post_uploads.upload_id
JOIN posts ON posts.id = post_uploads.post_id
ORDER BY uploads.filesize DESC
LIMIT 50

```

I get a message:

```plaintext
PG::UndefinedTable: ERROR: relation "post_uploads" does not exist
LINE 13: FROM post_uploads
              ^

```

For those who will find this topic in the future, it is related to [Search attachments by storage name](https://meta.discourse.org/t/search-attachments-by-storage-name/209945)

---

<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 31, 2023, 3:16pm UTC](https://meta.discourse.org/t/top-50-largest-uploads-broken-script/284017/2 "2023-10-31T15:16:33Z")

</div>

Ah yes. The `post_uploads` table has been deprecated. I think it needs to use the `uploads` and `upload_references` tables now?

Thanks for the report. 👍

> <https://github.com/discourse/discourse-data-explorer/blob/main/lib/discourse_data_explorer/queries.rb#L353>

* * *

I think this is the updated version if you need it @Ivan_Rapekas:

```sql
SELECT posts.id AS post_id,
    uploads.original_filename,
    ROUND(uploads.filesize / 1000000.0, 2) AS size_in_mb,
    uploads.extension,
    uploads.created_at,
    uploads.url
FROM upload_references
JOIN uploads ON uploads.id = upload_references.upload_id
JOIN posts ON posts.id = upload_references.target_id AND upload_references.target_type = 'Post'
ORDER BY uploads.filesize DESC
LIMIT 50

```

---

<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: [November 13, 2023, 10:32am UTC](https://meta.discourse.org/t/top-50-largest-uploads-broken-script/284017/4 "2023-11-13T10:32:46Z")

</div>

This should be fixed by: 👍

[https://github.com/discourse/discourse-data-explorer/pull/261](https://github.com/discourse/discourse-data-explorer/pull/261)

---

<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: [November 16, 2023, 10:34am UTC](https://meta.discourse.org/t/top-50-largest-uploads-broken-script/284017/5 "2023-11-16T10:34:11Z")

</div>

This topic was automatically closed after 3 days. New replies are no longer allowed.
