Backslash Escape Sequences

From: Andy Anderson <aanderson(at)amherst(dot)edu>
To: pgsql-docs(at)postgresql(dot)org
Subject: Backslash Escape Sequences
Date: 2008-04-30 18:26:00
Message-ID: 0108EC19-3397-4D79-8F05-F1AA1BDAE48B@amherst.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs pgsql-general

On the list pgsql-general, I had this exchange:

>>> Andy Anderson <aanderson(at)amherst(dot)edu> writes:
>>>> In a test I just did, the sequence \" (backslash double-quote) is
>>>> interpreted as just a " inside of the E'...' string constant
>>>> expression. This is great, since PHP's addslashes() sticks them
>>>> in along with the other stuff I really need to quote like ' and
>>>> \. But I see that \" isn't documented in the manual in section
>>>> 4.1.2.1. I assume this is, in fact, standard behavior for
>>>> Postgres? (Perhaps a comprehensive table might be a good idea at
>>>> this point in the manual.)
>>
>> Tom Lane wrote:
>>> Huh? It says
>>>
>>> Any other character following a backslash is taken literally.
>>>
>>>
>
> Andy Anderson wrote:
>> Ah, slight ambiguity here. Perhaps this might best say "Any other
>> character following a backslash is taken literally, and the
>> backslash is removed."

In any case, here's a contribution to the manual, a short table with
this information, in a format that might help make the subject
clearer. Modify at will!

-- Andy

<!--<TABLE BORDER="1" CLASS="CALSTABLE"> <COL><COL><COL> <THEAD> <TR>
<TH>Backslash Escape Sequence</TH> <TH>Interpretation</TH> <TH>Notes</
TH> </TR> </THEAD> <TBODY> <TR> <TD><TT CLASS="TOKEN">\b</TT></TD>
<TD>backspace</TD> <TD></TD> </TR> <TR> <TD><TT CLASS="TOKEN">\f</TT></
TD> <TD>form feed</TD> <TD></TD> </TR> <TR> <TD><TT CLASS="TOKEN">\n</
TT></TD> <TD>newline</TD> <TD></TD> </TR> <TR> <TD><TT CLASS="TOKEN">
\r</TT></TD> <TD>carriage return</TD> <TD></TD> </TR> <TR> <TD><TT
CLASS="TOKEN">\t</TT></TD> <TD>tab</TD> <TD></TD> </TR> <TR> <TD> <TT
CLASS="TOKEN">\<var>o</var></TT><br> <TT CLASS="TOKEN">\<var>oo</var></
TT><br> <TT CLASS="TOKEN">\<var>ooo</var></TT><br> </TD> <TD> octal
byte value </TD> <TD> <var>o</var> = 0 - 7 </TD> </TR> <TR> <TD> <TT
CLASS="TOKEN">\x<var>h</var></TT><br> <TT CLASS="TOKEN">\x<var>hh</
var></TT><br> </TD> <TD> hexadecimal byte value </TD> <TD> <var>h</
var> = 0 - F </TD> </TR> <TR> <TD><TT CLASS="TOKEN">\</TT><var>a</
var></TD> <TD><var>a</var></TD> <TD><var>a</var> = any other
character. Commonly used to include \ and '</TD> </TR> </TBODY> </
TABLE>-->

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Alvaro Herrera 2008-04-30 22:04:28 Re: Backslash Escape Sequences
Previous Message Andy Anderson 2008-04-30 16:51:45 Re: Quoting "

Browse pgsql-general by date

  From Date Subject
Next Message Benoît Carpentier 2008-04-30 18:59:12 Benetl 1.8, free ETL tool using postgreSQL is out !!!
Previous Message dan 2008-04-30 17:36:15 Re: Deadlock situation?