From bb3cce4ec9cc157a8dfc80b5b1770c2beac0a57e Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Sun, 26 Jun 2005 03:04:37 +0000 Subject: Add E'' syntax so eventually normal strings can treat backslashes literally. Add GUC variables: "escape_string_warning" - warn about backslashes in non-E strings "escape_string_syntax" - supports E'' syntax? "standard_compliant_strings" - treats backslashes literally in '' Update code to use E'' when escapes are used. --- doc/src/sgml/runtime.sgml | 57 ++++++++++++++++++++++++++++++++++++++++++++++- doc/src/sgml/syntax.sgml | 23 +++++++++++++++---- 2 files changed, 75 insertions(+), 5 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/runtime.sgml b/doc/src/sgml/runtime.sgml index 43334453921..3841b0dee2d 100644 --- a/doc/src/sgml/runtime.sgml +++ b/doc/src/sgml/runtime.sgml @@ -1,5 +1,5 @@ @@ -3757,6 +3757,30 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir' + + escape_string_warning (boolean) + stringsescape + + escape_string_warning configuration parameter + + + + When on, a warning is issued if a backslash + (\) appears in a ordinary, non-escape syntax + ('') string. To log the statement that generated the + warning, set log_min_error_statement to + error. The default is off. + + + Escape string syntax (E'') should be used for + escapes, because in future versions of + PostgreSQL ordinary strings will have + the standard-compliant behavior of treating backslashes + literally. + + + + @@ -3964,6 +3988,37 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir' + + escape_string_syntax (boolean) + stringsescape + + escape_string_syntax configuration parameter + + + + Reports whether escape string syntax (E'') is + supported. This variable is used by applications that need to + determine if escape string syntax can be used in their code. + + + + + + standard_compliant_strings (boolean) + stringsescape + + standard_compliant_strings configuration parameter + + + + Reports whether ordinary, non-escape syntax strings + ('') treat backslashes literally, as specified in + the SQL standard. This variable is used by applications that + need to know how ordinary strings are processed`. + + + + diff --git a/doc/src/sgml/syntax.sgml b/doc/src/sgml/syntax.sgml index 45b6a80564b..3d8d457c561 100644 --- a/doc/src/sgml/syntax.sgml +++ b/doc/src/sgml/syntax.sgml @@ -1,5 +1,5 @@ @@ -247,9 +247,10 @@ UPDATE "my_table" SET "a" = 5; write two adjacent single quotes, e.g. 'Dianne''s horse'. PostgreSQL also allows single quotes - to be escaped with a backslash (\), so for - example the same string could be written - 'Dianne\'s horse'. + to be escaped with a backslash (\'). However, + future versions of PostgreSQL will not + support this so applications using this should convert to the + standard-compliant method outlined above. @@ -268,6 +269,20 @@ UPDATE "my_table" SET "a" = 5; include a backslash in a string constant, write two backslashes. + + + While ordinary strings now support C-style backslash escapes, + future versions will generate warnings for such usage and + eventually treat backslashes as literal characters to be + standard-compliant. The proper way to specify escape processing is + to use the escape string syntax to indicate that escape + processing is desired. Escape string syntax is specified by placing + the the letter E (upper or lower case) before + the string, e.g. E'\041'. This method will work in all + future versions of PostgreSQL. + + + The character with the code zero cannot be in a string constant. -- cgit v1.2.3