paste -sd, - joins lines with commas. The operation is trivial and, like quoting, is only correct under an assumption about the data.
The delimiter collision
A value containing a comma, joined with commas, is indistinguishable from two values. The output is well-formed and wrong, and splitting it again does not recover the original. Check whether the delimiter occurs in any value before choosing it โ or pick one that cannot occur, which is why pipes and tabs are common choices for machine-readable output.
Trailing separators break parsers
Building the string by appending value + delimiter in a loop leaves a trailing delimiter, which many parsers read as a final empty value. Use the language's join on an array; it places separators between elements rather than after each one, which is the correct semantics and removes the whole class of bug.
Empty input is a real case
Joining an empty list gives an empty string, which as a query parameter or an IN clause is a syntax error rather than an empty set. Handle the zero-length case explicitly instead of letting it produce malformed output downstream.
Try it: Join Lines into a Delimited String on SeoWolf's Notepad.