Обсуждение: array quotation problem

Поиск
Список
Период
Сортировка

array quotation problem

От
Sim Zacks
Дата:
select version();
"PostgreSQL 8.0.1 on i686-pc-linux-gnu, compiled by GCC i686-pc-linux-gnu-gcc (GCC) 3.3.5  (Gentoo
Linux 3.3.5-r1, ssp-3.3.2-3, pie-8.7.7.1)"

In short:
Does anyone have any idea of how to put non escaped quotes into a text array element in the same way
that the system puts non escaped quotes around the text of an element that has whitespace within?

Details:
I am using a text array and when there are spaces in the text, the parser automatically puts double
quotes around the element and when there are no special characters it doesn't, as is written in the
documentation.

I would like to put double quotes around all the elements, even the ones without special characters
and I can't figure out how. The double quotes that the system automatically puts in are not escaped
with a \, but when I add quotes they are escaped (again as written in the documentation). If have
tried using chr(32) and quote_ident() and they work the same way.

My specific problem is that I am passing the array into a python function and converting it to a
python list type. The array gets passed in as a comma delimited string. If the values are already
quoted (without escapes) then it can be converted automatically. Otherwise I have to write a parsing
routine to check which of the elements have quotes (the ones that had a space) and which don't and
then to put in the quotes manually before I can convert it to a list type.

According to the documentation:
> The array output routine will put double quotes around element values if they are empty strings,
> contain curly braces, delimiter characters, double quotes, backslashes, or white space, or
 > match the word NULL. Double quotes and backslashes embedded in element values will be
backslash-escaped.
> For numeric data types it is safe to assume that double quotes will never appear, but for textual
> data types one should be prepared to cope with either presence or absence of quotes.

Re: array quotation problem

От
Sim Zacks
Дата:
I solved my specific problem by converting the array to a python as follows:
objlist=arr_text[1:-1].replace('"','').split(",")
This removes the quotes in any element that had it already, and then makes a list out of the string
separated by commas.
I'm still curious if it is possible to put the quotes into an array, so if you have an idea, give a
shout.

Sim Zacks wrote:
> select version();
> "PostgreSQL 8.0.1 on i686-pc-linux-gnu, compiled by GCC
> i686-pc-linux-gnu-gcc (GCC) 3.3.5  (Gentoo Linux 3.3.5-r1, ssp-3.3.2-3,
> pie-8.7.7.1)"
>
> In short:
> Does anyone have any idea of how to put non escaped quotes into a text
> array element in the same way that the system puts non escaped quotes
> around the text of an element that has whitespace within?
>
> Details:
> I am using a text array and when there are spaces in the text, the
> parser automatically puts double quotes around the element and when
> there are no special characters it doesn't, as is written in the
> documentation.
>
> I would like to put double quotes around all the elements, even the ones
> without special characters and I can't figure out how. The double quotes
> that the system automatically puts in are not escaped with a \, but when
> I add quotes they are escaped (again as written in the documentation).
> If have tried using chr(32) and quote_ident() and they work the same way.
>
> My specific problem is that I am passing the array into a python
> function and converting it to a python list type. The array gets passed
> in as a comma delimited string. If the values are already quoted
> (without escapes) then it can be converted automatically. Otherwise I
> have to write a parsing routine to check which of the elements have
> quotes (the ones that had a space) and which don't and then to put in
> the quotes manually before I can convert it to a list type.
>
> According to the documentation:
>> The array output routine will put double quotes around element values
>> if they are empty strings, contain curly braces, delimiter characters,
>> double quotes, backslashes, or white space, or
>  > match the word NULL. Double quotes and backslashes embedded in
> element values will be backslash-escaped.
>> For numeric data types it is safe to assume that double quotes will
>> never appear, but for textual
>> data types one should be prepared to cope with either presence or
>> absence of quotes.