Backslash Escape Sequences

Поиск
Список
Период
Сортировка
Искать

Backslash Escape Sequences

От:
Andy Anderson <aanderson@amherst.edu>
Дата:
On the list pgsql-general, I had this exchange:

>>> Andy Anderson  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


Re: Backslash Escape Sequences

От:
Alvaro Herrera <alvherre@commandprompt.com>
Дата:
Andy Anderson wrote:

> 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!

FWIW if you really want to make a contribution to the docs, please see
the SGML sources instead of the HTML output (which is machine-generated).

http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/doc/src/sgml/

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

Re: Backslash Escape Sequences

От:
Andy Anderson <aanderson@amherst.edu>
Дата:
>> Andy Anderson wrote:
>>
>>> 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!

> On Apr 30, 2008, at 6:04 PM, Alvaro Herrera wrote:
>> FWIW if you really want to make a contribution to the docs, please  
>> see
>> the SGML sources instead of the HTML output (which is machine- 
>> generated).

OK, then, I hope the following is accurate enough SGML to be more  
useful. Submitted here per the instructions on .

-- Andy

********************************************************************


	Backslash Escape Sequences
	
		
			
				Backslash Escape Sequence</>
				Interpretation
			
		
			
				\b
				backspace
			
			
				\f
				form feed
			
			
				\n
				newline
			
			
				\r
				carriage return
			
			
				\t
				tab
			
			
				
					
						\o
						\oo
						\ooo
						(o = 0 - 7)
					
				
				octal byte value
			
			
				
					
						\xh
						\xhh
						(h = 0 - F)
					
				
				hexadecimal byte value
			
			
				
					
						\a
						(a = any other character than the  
above,
						e.g. \ and '.)
					
				
				a
			
		

Re: Backslash Escape Sequences

От:
Bruce Momjian <bruce@momjian.us>
Дата:
Andy Anderson wrote:
> >> Andy Anderson wrote:
> >>
> >>> 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!
> 
> > On Apr 30, 2008, at 6:04 PM, Alvaro Herrera wrote:
> >> FWIW if you really want to make a contribution to the docs, please  
> >> see
> >> the SGML sources instead of the HTML output (which is machine- 
> >> generated).
> 
> OK, then, I hope the following is accurate enough SGML to be more  
> useful. Submitted here per the instructions on         http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +
Index: doc/src/sgml/syntax.sgml
===================================================================
RCS file: /cvsroot/pgsql/doc/src/sgml/syntax.sgml,v
retrieving revision 1.122
diff -c -c -r1.122 syntax.sgml
*** doc/src/sgml/syntax.sgml	20 Mar 2008 21:42:47 -0000	1.122
--- doc/src/sgml/syntax.sgml	26 Jun 2008 22:24:11 -0000
***************
*** 286,304 ****
       quote.)
       Within an escape string, a backslash character (\</>) begins a
       C-like backslash escape</> sequence, in which the combination
!      of backslash and following character(s) represents a special byte value.
!      \b is a backspace,
!      \f is a form feed,
!      \n is a newline,
!      \r is a carriage return,
!      \t is a tab.
!      Also supported are
!      \digits, where
!      digits represents an octal byte value, and
!      \xhexdigits, where
!      hexdigits represents a hexadecimal byte value.
!      (It is your responsibility that the byte sequences you create are
!      valid characters in the server character set encoding.) Any other
       character following a backslash is taken literally. Thus, to
       include a backslash character, write two backslashes (\\</>).
       Also, a single quote can be included in an escape string by writing
--- 286,348 ----
       quote.)
       Within an escape string, a backslash character (\</>) begins a
       C-like backslash escape</> sequence, in which the combination
!      of backslash and following character(s) represent a special byte
!      value:
! 
!      
!       Backslash Escape Sequences
!       
!       
!        
!         Backslash Escape Sequence</>
!         Interpretation
!        
!       
! 
!       
!        
!         \b
!         backspace
!        
!        
!         \f
!         form feed
!        
!        
!         \n
!         newline
!        
!        
!         \r
!         carriage return
!        
!        
!         \t
!         tab
!        
!        
!         
!          \o,
!          \oo,
!          \ooo
!          (o = 0 - 7)
!         
!         octal byte value
!        
!        
!         
!          \xh,
!          \xhh
!          (h = 0 - 9, A - F)
!         
!         hexadecimal byte value
!        
!       
!       
!      
! ! It is your responsibility that the byte sequences you create are ! valid characters in the server character set encoding. Any other character following a backslash is taken literally. Thus, to include a backslash character, write two backslashes (\\</>). Also, a single quote can be included in an escape string by writing

Re: Backslash Escape Sequences

От:
Alvaro Herrera <alvherre@commandprompt.com>
Дата:
Bruce Momjian wrote:

> > OK, then, I hope the following is accurate enough SGML to be more
> > useful. Submitted here per the instructions on
> >  
> Good idea --- a table is certainly clearer.  I modified your patch and
> applied the attached version.  Thanks much.

Hmm, I think the \\ and \' stuff should be part of that table too -- the
\a</> as in the patch seemed fine.

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.
FAQ