Presets
The same column, alice, bob, O'Brien, with each preset:
| Preset | Output |
|---|---|
| a, b, c | alice, bob, O'Brien |
| SQL IN ('a', 'b') | ('alice', 'bob', 'O''Brien') |
| JSON ["a", "b"] | ["alice", "bob", "O'Brien"] |
| a,b,c | alice,bob,O'Brien |
| a|b (regex) | alice|bob|O'Brien |
Joining and splitting lists in code
paste -sd, ids.txt # a,b,c
sed "s/'/''/g; s/.*/'&'/" ids.txt | paste -sd, - # 'a','b','O''Brien'
tr ',' '\n' <<< "a,b,c" # back to one per line
items = text.splitlines()
", ".join(items)
json.dumps(items) # ["a", "b", "c"]
# For SQL, use query parameters rather than building the IN list by hand
cur.execute("SELECT * FROM users WHERE id = ANY(%s)", (items,)) # psycopg
const items = text.split('\n').map((s) => s.trim()).filter(Boolean);
items.join(', ');
JSON.stringify(items);
'a, b,c'.split(/\s*,\s*/); // back to an array
Building SQL by hand from a list is fine for one-off queries in a console. In application code, pass the values as query
parameters so they’re escaped by the driver. Need to insert whole rows? CSV to SQL generates
INSERT statements.
Frequently asked questions
How do I turn a spreadsheet column into a comma-separated list?
Copy the cells from Excel or Google Sheets and paste them into the input: each cell arrives on its own line. The output is the values joined with a comma and a space. Pick a preset to quote them for SQL or JSON instead.
How are quotes inside values escaped?
In the way the target language expects. With single quotes, used by SQL, a quote inside a value is doubled, so O’Brien written with a straight apostrophe becomes 'O''Brien'. With double quotes or backticks, as in JSON and JavaScript, the quote and any backslash get a backslash in front. The values stay valid when pasted into a query or code.
Can I convert a comma-separated list back into a column?
Yes. Choose “List → column”. The prefix and suffix (like ( ) or [ ]) are stripped, quoted items are unquoted and unescaped, and commas inside quotes don’t split an item. The delimiter is matched with or without the space after it, and line breaks also separate items.
Is there a limit on SQL IN lists?
It depends on the database. Oracle allows at most 1,000 literal values in an IN list. SQL Server and PostgreSQL accept many more, but very long lists slow down query parsing; for thousands of values, load them into a temporary table and join, or in PostgreSQL pass an array: WHERE id = ANY($1).