1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-31 22:04:40 +03:00

Fix array_out's failure to backslash backslashes, per bug# 524. Also,

remove brain-dead rule that double quotes are needed if and only if the
datatype is pass-by-reference; neither direction of the implication holds
water.  Instead, examine the actual data string to see if it contains
any characters that force us to quote it.
Add some documentation about quoting of array values, which was previously
explained nowhere AFAICT.
This commit is contained in:
Tom Lane
2001-11-29 21:02:41 +00:00
parent a4e8cd306c
commit 636a939fe5
3 changed files with 109 additions and 59 deletions

View File

@ -1,4 +1,4 @@
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/array.sgml,v 1.17 2001/11/28 20:49:09 petere Exp $ -->
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/array.sgml,v 1.18 2001/11/29 21:02:41 tgl Exp $ -->
<chapter id="arrays">
<title>Arrays</title>
@ -248,4 +248,36 @@ SELECT * FROM sal_emp WHERE pay_by_quarter **= 10000;
</para>
</note>
<formalpara>
<title>Quoting array elements.</title>
<para>
As shown above, when writing an array literal value you may write double
quotes around any individual array
element. You <emphasis>must</> do so if the element value would otherwise
confuse the array-value parser. For example, elements containing curly
braces, commas, double quotes, backslashes, or white space must be
double-quoted. To put a double quote or backslash in an array element
value, precede it with a backslash.
</para>
</formalpara>
<tip>
<para>
Remember that what you write in an SQL query will first be interpreted
as a string literal, and then as an array. This doubles the number of
backslashes you need. For example, to insert a <type>text</> array
value containing a backslash and a double quote, you'd need to write
<programlisting>
INSERT ... VALUES ('{"\\\\","\\""}');
</programlisting>
The string-literal processor removes one level of backslashes, so that
what arrives at the array-value parser looks like <literal>{"\\","\""}</>.
In turn, the strings fed to the <type>text</> datatype's input routine
become <literal>\</> and <literal>"</> respectively. (If we were working
with a datatype whose input routine also treated backslashes specially,
<type>bytea</> for example, we might need as many as eight backslashes
in the query to get one backslash into the stored array element.)
</para>
</tip>
</chapter>