I'm trying to find the documentation of a complete list of escape sequences for string data types in Postgresql. So for example, if you need to escape a quote character inside of a quoted string, you would use \". Different DBMSs use different jargon, so I'm having a hard time finding what to search for.

I found this, but it doesn't look exhaustive to me. In this link, search for "The following special backslash sequences are recognized by COPY FROM".



I knew it wasn't exhaustive. See the \\ character here:


Then look at " String Constants with C-style Escapes" in this link. Also read what's written in CAUTION. This is making me humble, and I hope it is for others.


  • 3
    "if you need to escape a quote character inside of a quoted string, you would use \" - no that's wrong. A " does not need to be "escaped" in a SQL string literal. The only character that needs escaping in SQL is the single quote itself and that is escaped by doubling it. 'Arthur''s House'. But the escape sequences for CSV input files used by the copy command have nothing to do with the syntax for SQL string literals. – a_horse_with_no_name Dec 15 '15 at 17:06
  • I'm looking for others as well... \n, \t, new line characters in data, etc... – MacGyver Dec 15 '15 at 17:36
  • What exactly are you trying to do? Is that for text files to be imported using copy or for SQL literals? – a_horse_with_no_name Dec 15 '15 at 17:50
  • 1
    You can also use the dollar-quote in situations you need to escape a lot of quotes. Example: SELECT $str$'la'lla' test ''$str$ – Pivobispo Dec 15 '15 at 19:28
  • 4
    I, too, think you are distracted by the wrong question. Consider: Insert varchar with single quotes in PostgreSQL – Erwin Brandstetter Dec 16 '15 at 5:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.