Skip to content
rusthacks.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.

Go deeper

Suggested reading

Flat illustration for the post “Testing Database Code in Rust With Test Containers”, composed around deploy.
Databases

Testing Database Code in Rust With Test Containers

Run tests against a real PostgreSQL in a disposable container with the testcontainers crate. Start one per test run, migrate, isolate tests with transactions or databases, and keep CI fast with reuse.

4 min read
Flat illustration for the post “Repository Pattern in Rust and Whether You Need It”, composed around traits.
Databases

Repository Pattern in Rust and Whether You Need It

A repository hides the database behind a trait. See when that helps (testing, swapping stores) and when it only adds indirection, with a concrete trait, an SQLx impl and an in-memory fake.

3 min read

Keep planning

Similar tools