Skip to content
gohacks.dev
Databases

List to Array or SQL IN Clause

Paste a column of values and get a SQL IN (...) list, a JSON, PHP or Python array, a Bash array, a YAML list or a CSV row, quoted correctly.

Free · No sign-up · Your inputs stay in your browser

Input

Turn a list into an array or SQL IN clause

Output

Result

39 characters

For an IN clause built from user input, bind the values instead: whereIn() in Laravel, or one ? placeholder per item.

Runs in this browser. Nothing you paste is sent to a server.

A one-off query, not application code

Pasting IDs from a spreadsheet into WHERE id IN (...) is a daily job when investigating data. In application code, bind the values instead, so nothing typed by a user ever becomes SQL: Laravel's whereIn('id', $ids) adds one placeholder per value.

Long lists

MySQL accepts very long IN lists, limited by max_allowed_packet, and turns a list of constants into a sorted lookup. PostgreSQL handles them too, but for thousands of values = ANY($1) with an array parameter, or a join against a temporary table, keeps the statement small and the plan cacheable.

Share

Frequently asked questions

How do I quote values for a SQL IN clause?
Wrap each in single quotes and double any single quote inside, so O'Brien becomes 'O''Brien'. Numbers can stay unquoted when the column is numeric.
Can I remove duplicates at the same time?
Yes, 'Remove duplicates' is on by default and keeps the first occurrence of each value.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools