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.
| Where | Text values use | Example line |
|---|---|---|
| SQL | Single quotes | 'Paris', |
| JSON | Double quotes only | "Paris", |
| JavaScript / TypeScript | Either, used consistently | 'Paris', |
| Python | Either, used consistently | "Paris", |
| CSV fields | Double quotes when needed | "Paris, France" |
Adding both quotes in two passes
- Add the opening quote as a prefix to each line.
- Add the closing quote — plus a comma if the values are listed — as a suffix.
- 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
- Add Commas to Each LineTurn a column of values into a comma-separated list for SQL, code, or data files — and handle the last comma, quotes, and blank lines correctly.
- Suffix After Invisible SpacesWhy text added to the end of a line can appear after a gap or even at its start, where hidden spaces and carriage returns come from, and how to trim them.
Open the tool
Jump into Add Suffix to Each Line when you are ready to process your files.
