Handle Quoted Strings and Escape Sequences in SQL Values

Extract SQL string values that contain single quotes, backslash escapes, commas, and newlines into properly escaped CSV fields.

Data Types

Detailed Explanation

String Escaping — SQL to CSV

SQL strings use single quotes and have their own escaping rules. CSV fields use double quotes (by default) with different escaping. The tool handles the translation automatically.

Example SQL

INSERT INTO articles (id, title, author, excerpt) VALUES
  (1, 'It''s a Wonderful Life', 'O''Brien, Frank', 'A classic film that''s beloved by many'),
  (2, 'The "Best" Guide', 'Jane Smith', 'Contains "quoted" text and commas, naturally'),
  (3, 'Line\nBreak Test', 'Test Author', 'First line\nSecond line\nThird line');

Generated CSV

id,title,author,excerpt
1,It's a Wonderful Life,"O'Brien, Frank",A classic film that's beloved by many
2,"The ""Best"" Guide",Jane Smith,"Contains ""quoted"" text and commas, naturally"
3,"Line
Break Test",Test Author,"First line
Second line
Third line"

Escaping Translation

SQL Escape Meaning CSV Result
'' (doubled quote) Literal single quote ' (unescaped)
\' (backslash quote) Literal single quote ' (unescaped)
\n Newline Actual newline (field gets quoted)
\t Tab Actual tab (field gets quoted if tab is delimiter)
\\\\ Literal backslash \\

CSV Quoting Rules (RFC 4180)

A CSV field is wrapped in double quotes when it contains:

  • The delimiter character (comma by default)
  • The quote character (double quote by default)
  • A newline character (\n or \r)

Double quotes within a quoted field are escaped by doubling them: "".

Use Case

Converting content management system data or blog article dumps where text fields frequently contain apostrophes, quotation marks, commas, and multi-line content.

Try It — SQL to CSV Converter

Open full tool