Created
October 6, 2019 17:15
-
-
Save simonw/656a8c6e4688f720773c474080abe1b0 to your computer and use it in GitHub Desktop.
Query a twitter-to-sqlite database and find the "deepest" tweets in a reply thread, adapted from https://gist.github.com/robinhouston/f689a4b833dc027a3fd97e3de855927b
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with recursive thread as ( | |
select id, in_reply_to_status_id, 0 as depth | |
from tweets | |
where in_reply_to_status_id is null | |
union | |
select tweets.id, tweets.in_reply_to_status_id, 1 + thread.depth as depth | |
from thread join tweets on tweets.in_reply_to_status_id = thread.id) | |
select * from thread order by depth desc |
Similar solution from Piers Cawley: https://twitter.com/pdcawley/status/1180898024832327680
WITH RECURSIVE threads(id, thread, depth) AS (
SELECT tw.id, tw.id, 1 FROM tweets tw WHERE in_reply_to_status_id IS NULL
UNION
SELECT tw.id, tw.id || ', ' || th.thread, th.depth + 1
FROM threads th
JOIN tweets tw ON th.id = tw.in_reply_to_status_id
)
select id, thread, depth from threads order by depth desc limit 10;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Variant using a suggestion from Matthew Somerville which adds the concatenated hierarchy of tweet IDs: