I have applied the E'' escape patch to CVS head.
I am attaching a smaller version that doesn't have the
escape_string_warning GUC and none of the adjustments to our code to use
E''.
I am thinking I should apply this to 8.0.X and 7.4.X? OK? Earlier
versions?
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
Index: doc/src/sgml/runtime.sgml
===================================================================
RCS file: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v
retrieving revision 1.301.4.7
diff -c -c -r1.301.4.7 runtime.sgml
*** doc/src/sgml/runtime.sgml 17 Jun 2005 16:46:45 -0000 1.301.4.7
--- doc/src/sgml/runtime.sgml 26 Jun 2005 03:19:52 -0000
***************
*** 3767,3772 ****
--- 3767,3803 ----
</listitem>
</varlistentry>
+ <varlistentry id="guc-escape-string-syntax" xreflabel="escape_string_syntax">
+ <term><varname>escape_string_syntax</varname> (<type>boolean</type>)</term>
+ <indexterm><primary>strings</><secondary>escape</></>
+ <indexterm>
+ <primary><varname>escape_string_syntax</> configuration parameter</primary>
+ </indexterm>
+ <listitem>
+ <para>
+ Reports whether escape string syntax (<literal>E''</>) is
+ supported. This variable is used by applications that need to
+ determine if escape string syntax can be used in their code.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry id="guc-sql-standard-strings" xreflabel="standard_compliant_strings">
+ <term><varname>standard_compliant_strings</varname> (<type>boolean</type>)</term>
+ <indexterm><primary>strings</><secondary>escape</></>
+ <indexterm>
+ <primary><varname>standard_compliant_strings</> configuration parameter</primary>
+ </indexterm>
+ <listitem>
+ <para>
+ Reports whether ordinary, non-escape syntax strings
+ (<literal>''</>) treat backslashes literally, as specified in
+ the SQL standard. This variable is used by applications that
+ need to know how ordinary strings are processed`.
+ </para>
+ </listitem>
+ </varlistentry>
+
</variablelist>
</sect2>
Index: doc/src/sgml/syntax.sgml
===================================================================
RCS file: /cvsroot/pgsql/doc/src/sgml/syntax.sgml,v
retrieving revision 1.99
diff -c -c -r1.99 syntax.sgml
*** doc/src/sgml/syntax.sgml 23 Dec 2004 05:37:40 -0000 1.99
--- doc/src/sgml/syntax.sgml 26 Jun 2005 03:19:53 -0000
***************
*** 247,255 ****
write two adjacent single quotes, e.g.
<literal>'Dianne''s horse'</literal>.
<productname>PostgreSQL</productname> also allows single quotes
! to be escaped with a backslash (<literal>\</literal>), so for
! example the same string could be written
! <literal>'Dianne\'s horse'</literal>.
</para>
<para>
--- 247,256 ----
write two adjacent single quotes, e.g.
<literal>'Dianne''s horse'</literal>.
<productname>PostgreSQL</productname> also allows single quotes
! to be escaped with a backslash (<literal>\'</literal>). However,
! future versions of <productname>PostgreSQL</productname> will not
! support this so applications using this should convert to the
! standard-compliant method outlined above.
</para>
<para>
***************
*** 267,272 ****
--- 268,287 ----
string constant, write two backslashes.
</para>
+ <note>
+ <para>
+ 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 <literal>E</literal> (upper or lower case) before
+ the string, e.g. <literal>E'\041'</>. This method will work in all
+ future versions of <productname>PostgreSQL</productname>.
+ </para>
+ </note>
+
<para>
The character with the code zero cannot be in a string constant.
</para>
Index: src/backend/parser/scan.l
===================================================================
RCS file: /cvsroot/pgsql/src/backend/parser/scan.l,v
retrieving revision 1.119
diff -c -c -r1.119 scan.l
*** src/backend/parser/scan.l 31 Dec 2004 22:00:27 -0000 1.119
--- src/backend/parser/scan.l 26 Jun 2005 03:19:54 -0000
***************
*** 167,173 ****
* xqcat allows strings to cross input lines
*/
quote '
! xqstart {quote}
xqstop {quote}
xqdouble {quote}{quote}
xqinside [^\\']+
--- 167,173 ----
* xqcat allows strings to cross input lines
*/
quote '
! xqstart [eE]?{quote}
xqstop {quote}
xqdouble {quote}{quote}
xqinside [^\\']+
Index: src/backend/utils/misc/guc.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v
retrieving revision 1.252.4.1
diff -c -c -r1.252.4.1 guc.c
*** src/backend/utils/misc/guc.c 25 Mar 2005 16:17:38 -0000 1.252.4.1
--- src/backend/utils/misc/guc.c 26 Jun 2005 03:19:57 -0000
***************
*** 185,190 ****
--- 185,192 ----
static int max_identifier_length;
static int block_size;
static bool integer_datetimes;
+ static bool escape_string_syntax;
+ static bool standard_compliant_strings;
/* should be static, but commands/variable.c needs to get at it */
char *session_authorization_string;
***************
*** 851,856 ****
--- 853,878 ----
#endif
},
+ {
+ {"escape_string_syntax", PGC_INTERNAL, PRESET_OPTIONS,
+ gettext_noop("Escape string syntax (E'') is supported."),
+ NULL,
+ GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
+ },
+ &escape_string_syntax,
+ true, NULL, NULL
+ },
+
+ {
+ {"standard_compliant_strings", PGC_INTERNAL, PRESET_OPTIONS,
+ gettext_noop("'' strings treat backslashes literally."),
+ NULL,
+ GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
+ },
+ &standard_compliant_strings,
+ false, NULL, NULL
+ },
+
/* End-of-list marker */
{
{NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL