Subject: show value of backslashes in string array argument
From: Sabin Coanda
Date: 11/12/2007 11:15:48 AM
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 character backslash,
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
Subject: show value of backslashes in string array argument
From: Sabin Coanda
Date: 11/12/2007 11:51:41 AM
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
Subject: show value of backslashes in string array argument
From: Sabin Coanda
Date: 11/12/2007 12:38:29 PM
>I would recommend:
>
>a) Move to Unix
>b) Subscribe to pgsql-jdbc@postgresql.org
Hi Achilleas,
I'm not very content of the answer, because it seems to be the language
problem, not the driver.
I'd reformulate the problem, to understand it better.
Suppose I build my own driver, that use the syntax SELECT ARRAY[
'\' ]::varchar[]; This is working well, just when I set
standard_conforming_strings = 'on'. Otherwise I have to use SELECT ARRAY[
'\\' ]::varchar[]; So an "intelligent" driver have to be aware too of the
own postgresq settings standard_conforming_strings = 'on', and call
statements according with it.
On the other hand, If my own driver would use the syntax SELECT
'{\\}'::varchar[];, it wouldn't be aware of standard_conforming_strings =
'on', because it would work for any value of standard_conforming_strings.
But if I'd like to build statements with varchar parameters, not varchar
arrays, I have no option than to be aware of standard_conforming_strings,
using SELECT '\' when it is on, and SELECT '\\' when it is off.
So being consistent with the two data types, it means for any parameter type
the format has to be different and aware of standard_conforming_strings. But
this is not the case with the notation SELECT '{\\}'::varchar[]; I'd see it
to be consistent just if at standard_conforming_strings = 'on' I'd get the
same result with SELECT '{\}'::varchar[]; but this is not working because of
the language.
Regards,
Sabin
Subject: show value of backslashes in string array argument
From: tgl@sss.pgh.pa.us (Tom Lane)
Date: 11/12/2007 11:05:27 AM
"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
---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?
http://www.postgresql.org/docs/faq
Subject: show value of backslashes in string array argument
From: Sabin Coanda
Date: 11/12/2007 7:12:36 PM
"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
|