I am working on my thesis and I need to get Stack Overflow datasets related to the "comments" ending with ".csv".
-
2See meta.stackexchange.com/questions/19579/…– Robert LongsonApr 18, 2022 at 13:57
-
21I think very few comments on StackOverflow end with ‘.csv’.– user3840170Apr 18, 2022 at 14:21
-
3@user3840170 precisely 832 as of today– Oleg Valter is with UkraineApr 18, 2022 at 14:24
-
14Why are comments ending with ".csv" interesting?– Peter MortensenApr 19, 2022 at 2:13
-
2What are some examples of such comments?– Peter MortensenApr 19, 2022 at 2:50
-
19I would also like to know.csv– user3840170Apr 19, 2022 at 9:14
-
6And that's another one.csv– AverageHomosapienApr 19, 2022 at 10:49
-
4Meanwhile, please allow me to get all SO comments and put them into a .csv.– AmessihelApr 19, 2022 at 21:02
3 Answers
If you don't want to download the datadump and don't want to fiddle with T-SQL in SEDE you can download about 500,000 comments in one go with this query. The query makes use of the PIVOT statement to spread row values across multiple columns.
declare @limitrows int = ##limit?100000##
declare @cols int = 10 -- if you change this
-- change the column labels as well
-- in two places !
select [row]
-- 10 cols
, [0]
, [1]
, [2]
, [3]
, [4]
, [5]
, [6]
, [7]
, [8]
, [9]
from
(select (seq-1) % @cols [col]
, row / @cols [row]
, text
from
( select top (@limitrows)
row_number() over(order by id) seq
, row_number() over(order by id) row
, text
from comments ) as c
) as ca
pivot (
min(text)
for ca.col in (
-- 10 cols
[0]
, [1]
, [2]
, [3]
, [4]
, [5]
, [6]
, [7]
, [8]
, [9])
) p
You first run the query and after you got a result, click the Download CSV button at the top right of the result grid. I indicated that button with a red free hand circle in the below screenshot:
I leave it as an exercise for the reader to parameterize the inner query that drives which comments get selected. The answer from Oleg Valter can be helpful with that.
Keep in mind SEDE is updated once a week on Sunday.
Use the excellent SEDE Tutorial written by the admirable Monica Cellio.
Say "Hi" in SEDE chat.
-
2Christ, that's a clever way to get the comments for later processing :) Apr 18, 2022 at 15:19
As an alternative to data dumps, you can use the Stack Exchange Data Explorer (aka SEDE). Although due to sheer number of comments on Stack Overflow, such a query is going to be slow due to the leading wildcard, but can fit into the execution time limit if you forgo the ordering:
select
*
from
comments
where
text like '%' + ##Ending:string##
Stack Exchange in general runs data dumps that are available for public consumption (list of all dumps can be found here). In particular, SO (due to the site's size) breaks data dumps into separate dumps. The March 17, 2022 dump of comments is here. You'll have to parse it for what you need, but it's the easiest way to compile the data you seek.
Good luck!