Illustration of list items wrapped in single quotes with commas, ready for a database query

Text & writing

How to Wrap Each Line in Quotes for Code and SQL

Pasting a list of names, IDs, or keywords into a query or a piece of code usually means wrapping each one in quotes and separating them with commas. Which quote to use, and what to do when a value already contains a quote, depends on the language.

Ready to try the tool this guide describes?

Which quote mark to use

In standard SQL, double quotes mean a column or table name, not a text value — using them for values is a common source of confusing errors.

Which quote mark to use comparison
WhereText values useExample line
SQLSingle quotes'Paris',
JSONDouble quotes only"Paris",
JavaScript / TypeScriptEither, used consistently'Paris',
PythonEither, used consistently"Paris",
CSV fieldsDouble quotes when needed"Paris, France"

Adding both quotes in two passes

  1. Add the opening quote as a prefix to each line.
  2. Add the closing quote — plus a comma if the values are listed — as a suffix.
  3. Remove the comma after the last line if the format does not allow a trailing comma.

Values that already contain quotes

Adding a prefix and suffix does not escape inner quotes, so search the list for quote marks first and fix those values by hand or with find and replace.

  • SQL: double an apostrophe inside a value — O'Brien becomes 'O''Brien'.
  • JSON and JavaScript double-quoted strings: put a backslash before an inner double quote — \".
  • CSV: double an inner double quote — "Say ""hi""".

Numbers and blank lines

Numeric IDs compared against a numeric column should normally be left unquoted. Blank lines should be removed or left without quotes; a pair of quotes on an empty line creates an empty string value.

Wrap Lines in Quotes FAQ

Should I use single or double quotes in SQL?
Single quotes for text values. Double quotes are for identifiers such as column names in standard SQL.
How do I handle a name with an apostrophe in SQL?
Double the apostrophe inside the value: O'Brien becomes 'O''Brien'.
Can JSON use single quotes?
No. JSON strings must use double quotes.
How do I wrap every line in quotes quickly?
Add the opening quote as a prefix to every line, then the closing quote (and a comma) as a suffix.
Should numbers be quoted?
Usually not when they are compared with a numeric column or used as numbers in code.

Related guides

Open the tool

Jump into Add Suffix to Each Line when you are ready to process your files.

← Back to all guides

More from Looty

Explore Looty’s Ecosystem

Discover more ways Looty can help you learn, organize, create, and make an impact.