# User posts export as csv or text

**URL:** https://meta.discourse.org/t/user-posts-export-as-csv-or-text/273232
**Category:** Data & reporting
**Tags:** sql-query
**Created:** [July 29, 2023, 3:34pm UTC](https://meta.discourse.org/t/user-posts-export-as-csv-or-text/273232 "2023-07-29T15:34:26Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![kynic](https://avatars.discourse-cdn.com/v4/letter/k/b487fb/32.png) [@kynic](https://meta.discourse.org/u/kynic)
#### Post date: [July 29, 2023, 3:34pm UTC](https://meta.discourse.org/t/user-posts-export-as-csv-or-text/273232/1 "2023-07-29T15:34:26Z")

</div>

Hi all,

I want to export a user’s posts as a text/CSV file do anyone know how I can achieve this with [data explorer](https://meta.discourse.org/t/32566) or any other way?

---

<div class="post-metadata">

### Author: ![kynic](https://avatars.discourse-cdn.com/v4/letter/k/b487fb/32.png) [@kynic](https://meta.discourse.org/u/kynic)
#### Post date: [July 29, 2023, 4:13pm UTC](https://meta.discourse.org/t/user-posts-export-as-csv-or-text/273232/2 "2023-07-29T16:13:57Z")

</div>

I found this code works for [data explorer](https://meta.discourse.org/t/32566?silent=true)

```plaintext
SELECT t.title, p.raw as text, p.created_at as dateposted
FROM posts p
LEFT JOIN topics t ON t.id = p.topic_id
WHERE t.archetype != 'private_message'
AND t.user_id = 1
AND p.user_id = 1
AND t.category_id IN (13,7,1,)
AND t.deleted_at is null

```

But it only shows 336 results is there any way to pass this limit? as there are around 5k posts.

---

<div class="post-metadata">

### Author: ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)
#### Post date: [July 29, 2023, 4:16pm UTC](https://meta.discourse.org/t/user-posts-export-as-csv-or-text/273232/3 "2023-07-29T16:16:15Z")

</div>

A user can request a full copy of their posts and other data in CSV format via the Export Your Data section of Preferences.

For example here on meta it’s at:

[https://meta.discourse.org/my/preferences/account](https://meta.discourse.org/my/preferences/account)

System will message them with a link to a zip file. The `user_archive.csv` contains the post data.

---

<div class="post-metadata">

### Author: ![kynic](https://avatars.discourse-cdn.com/v4/letter/k/b487fb/32.png) [@kynic](https://meta.discourse.org/u/kynic)
#### Post date: [July 29, 2023, 5:18pm UTC](https://meta.discourse.org/t/user-posts-export-as-csv-or-text/273232/4 "2023-07-29T17:18:21Z")

</div>

But this includes PM also and I want only public posts.

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [July 31, 2023, 12:15pm UTC](https://meta.discourse.org/t/user-posts-export-as-csv-or-text/273232/5 "2023-07-31T12:15:55Z")

</div>

> [@kynic](#):
>
> But it only shows 336 results is there any way to pass this limit? as there are around 5k posts.

Isn’t that because the 5000 posts include PMs (maybe deleted messages as well) and you filter your categories?

---

<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: [July 31, 2023, 12:20pm UTC](https://meta.discourse.org/t/user-posts-export-as-csv-or-text/273232/6 "2023-07-31T12:20:06Z")

</div>

Including `t.user_id` would only give posts where the user was also the OP. Could that be the main issue?

I noticed a couple of extra bits that may be useful too. Something like:

```sql
-- [params]
-- user_id :user

SELECT t.id AS topic_id, 
       t.title, 
       p.raw as text, 
       p.created_at as dateposted
FROM posts p
JOIN topics t ON t.id = p.topic_id
WHERE t.archetype != 'private_message'
  AND p.post_type IN (1, 4)
  AND p.user_id = :user
  AND t.deleted_at ISNULL
  AND p.deleted_at ISNULL
ORDER BY p.created_at

```
