Meta: Threads Posts Cut Off in the Feed Preview
On a compact feed card, Threads shows only the first 40 characters of a post and adds an ellipsis.
- Difficulty: Easy
- Topics: Strings
- Dialect: MySQL
- Problem: #752
Problem statement
On a compact feed card, Threads shows only the first 40 characters of a post and adds an ellipsis. A designer wants to see exactly what those cards will look like.
Return every post whose body is longer than 40 characters, with the columns post_id and preview — the first 40 characters of the body followed by ... (three dots). A post of exactly 40 characters fits and is not returned. Return the rows ordered by post_id.
A practice scenario set at Meta: the tables and data are invented, and this is not a question from, or endorsed by, Meta.
Tables
Table: ThreadsPost
| Column | Type |
|---|---|
| post_id | int |
| author_handle | varchar |
| body | varchar |
| posted_at | datetime |
Primary key: post_id.
One row per Threads post. body is plain text (letters, digits, spaces, punctuation) and is never NULL.
Examples
Example 1
ThreadsPost
| post_id | author_handle | body | posted_at |
|---|---|---|---|
| 1 | chai.coder | Shipping a new feature today, wish me luck | 2025-08-01 09:15:00 |
| 2 | mumbai.rains | Who else is watching the match tonight?? | 2025-08-01 19:40:00 |
| 3 | tabs.forever | Hot take: tabs beat spaces, fight me | 2025-08-02 11:05:00 |
| 4 | run.priya | Finished my first marathon in under five hours!! | 2025-08-03 07:30:00 |
| 5 | late.night.dev | Chai or coffee for a late night debug run | 2025-08-03 23:55:00 |
Output
| post_id | preview |
|---|---|
| 1 | Shipping a new feature today, wish me lu... |
| 4 | Finished my first marathon in under five... |
| 5 | Chai or coffee for a late night debug ru... |
How to solve Meta: Threads Posts Cut Off in the Feed Preview
Two string functions do the work. The filter is a length test: CHAR_LENGTH(body) > 40 keeps only the posts the card would cut, and the strict > lets a post of exactly 40 characters through untouched, since it fits. The preview is the visible part plus the marker: LEFT(body, 40) takes the first 40 characters and CONCAT(…, '...') appends the three dots.
CHAR_LENGTH counts characters, while LENGTH counts bytes in MySQL; for this plain ASCII text they agree, which is why the alternative's LENGTH(body) >= 41 gives the same rows, and SUBSTRING(body, 1, 40) is the same cut as LEFT. On text with emoji or Devanagari the byte count would be larger, so CHAR_LENGTH is the safer habit.
The statement fixes the order, so the query ends with ORDER BY post_id. It is one scan of the table.
Reference solution (MySQL)
SELECT post_id, CONCAT(LEFT(body, 40), '...') AS preview
FROM ThreadsPost
WHERE CHAR_LENGTH(body) > 40
ORDER BY post_idAnother way
SELECT post_id, CONCAT(SUBSTRING(body, 1, 40), '...') AS preview FROM ThreadsPost WHERE LENGTH(body) >= 41 ORDER BY post_id← Meta: Ad Accounts That Overspent Their September Limit · Meta: Messenger Video Call Minutes by Day of the Week →