Обсуждение: show value of backslashes in string array argument
Hi there,
I have a problem using backslash character as part of a string array item.
I use "PostgreSQL 8.2.4 on i686-pc-mingw32, compiled by GCC gcc.exe (GCC)
3.4.2 (mingw-special)" version, with standard_conforming_strings = 'on'.
I found that, is that in spite of using standard_conforming_strings = 'on',
the string array items are shown in C escape sequences conventions.
Use the following scenario: - create a table with CREATE TABLE test ( "colVarchar" character
varying, "colVarcharArray" character varying[] ) - insert a row with a string composed by just one
characterbackslash,
and an array with just one item, with the same value of one backslash, with: INSERT INTO test VALUES ( '\',
ARRAY['\' ] ); - show the values with: SELECT * FROM test
And the result is:
colVarchar | colVarcharArray
------------+-----------------\ | {"\\"}
The question is why the two strings are shown different in spite they are
the same, and standard_conforming_strings = 'on' ?
Sabin
If you do SELECT "colVarchar","colVarcharArray"[1] FROM test; you will see that you get identical values. -- Achilleas Mantzios
I fond another collateral problem, because there are the different
convention to describe a varchar array item which contains backslashes, when
standard_conforming_strings = 'on'
For instance, to get a string composed by just one character backslash I can
use any of the two forms:
SELECT ARRAY[ '\' ]::varchar[];
or
SELECT '{\\}'::varchar[];
On the other hand, standard_conforming_strings = 'on' let me use varchar
items with '\' format. So the first format seems to be aware of
standard_conforming_strings = 'on', but the second is not.
My problem is that the java driver build arrays using the second format, but
the driver seems to be aware of standard_conforming_strings = 'on'. This
make inconsistence using the statement parameters, because to get the same
thing in the database I have to initialize a varchar parameter with a string
of one backslashes, but a varchar array item has to be initialized with a
string of two backslashes.
Sabin
Στις Δευτέρα 12 Νοέμβριος 2007 11:51, ο/η Sabin Coanda έγραψε:
> I fond another collateral problem, because there are the different
> convention to describe a varchar array item which contains backslashes,
> when standard_conforming_strings = 'on'
>
> For instance, to get a string composed by just one character backslash I
> can use any of the two forms:
>
> SELECT ARRAY[ '\' ]::varchar[];
>
> or
>
> SELECT '{\\}'::varchar[];
>
> On the other hand, standard_conforming_strings = 'on' let me use varchar
> items with '\' format. So the first format seems to be aware of
> standard_conforming_strings = 'on', but the second is not.
>
> My problem is that the java driver build arrays using the second format,
> but the driver seems to be aware of standard_conforming_strings = 'on'.
> This make inconsistence using the statement parameters, because to get the
> same thing in the database I have to initialize a varchar parameter with a
> string of one backslashes, but a varchar array item has to be initialized
> with a string of two backslashes.
>
> Sabin
I would recommend:
a) Move to Unix
b) Subscribe to pgsql-jdbc@postgresql.org
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: You can help support the PostgreSQL project by donating at
>
> http://www.postgresql.org/about/donate
--
Achilleas Mantzios
"Sabin Coanda" <sabin.coanda@deuromedia.ro> writes: > I found that, is that in spite of using standard_conforming_strings = 'on', > the string array items are shown in C escape sequences conventions. That's how it's supposed to be. See http://www.postgresql.org/docs/8.2/static/arrays.html#AEN5876 regards, tom lane
"Tom Lane" <tgl@sss.pgh.pa.us> wrote in message news:6268.1194883527@sss.pgh.pa.us... > That's how it's supposed to be. See > http://www.postgresql.org/docs/8.2/static/arrays.html#AEN5876 Hi Tom, I read it and I understood there are 2 cascaded parsers, but I didn't find an explicit reference to the behavior related to standard_conforming_strings. But after some tests, I found the following behaviors: - the 1st parser is the SQL interpreter which is aware of standard_conforming_strings (on or off) - the 2nd parser which is an array interpreter, doesn't care of standard_conforming_strings, using every time C escape conventions Please confirm me whether I understand it correctly or not. TIA, Sabin