5

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".

http://www.postgresql.org/docs/9.5/static/sql-copy.html

EDIT:

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

http://www.postgresql.org/docs/8.3/static/sql-syntax-lexical.html

Then look at "4.1.2.2. 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.

http://www.postgresql.org/docs/9.2/static/sql-syntax-lexical.html

7
  • 4
    "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. Commented Dec 15, 2015 at 17:06
  • I'm looking for others as well... \n, \t, new line characters in data, etc... Commented Dec 15, 2015 at 17:36
  • What exactly are you trying to do? Is that for text files to be imported using copy or for SQL literals? Commented Dec 15, 2015 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$ Commented Dec 15, 2015 at 19:28
  • 4
    I, too, think you are distracted by the wrong question. Consider: Insert varchar with single quotes in PostgreSQL Commented Dec 16, 2015 at 5:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.