Thread: problem with to_ascii() function in version 8.3.3

problem with to_ascii() function in version 8.3.3

From
Pavel Arnošt
Date:
Hi,

i have a problem with to_ascii() function in version 8.3.3. I have
read Mr. Gonzales's post at

http://groups.google.com/group/pgsql.general/browse_thread/thread/f74650e3b3248ff0/9f36fb072ea1dc98?lnk=gst&q=to_ascii#9f36fb072ea1dc98
and he managed to use to_ascii function with following command
sequence:

create table chartest ( c text);
insert into chartest (c) values ('á');
select to_ascii(encode(convert_to(c,'LATIN9'),'escape'),'LATIN9') from
chartest;

His output was:

to_ascii
----------
 a

but i'm getting:

 to_ascii
----------
 \341

What am I doing wrong? How to_ascii function should be used?

Regards
Pavel Arnošt

Re: problem with to_ascii() function in version 8.3.3

From
"Albe Laurenz"
Date:
Pavel Arnošt wrote:
> i have a problem with to_ascii() function in version 8.3.3. I have read Mr. Gonzales's post at
>
http://groups.google.com/group/pgsql.general/browse_thread/thread/f74650e3b3248ff0/9f36fb072ea1dc98?lnk=gst&q=to_ascii#9f36fb072ea1dc98
> and he managed to use to_ascii function with following command
> sequence:
>
> create table chartest ( c text);
> insert into chartest (c) values ('á');
> select to_ascii(encode(convert_to(c,'LATIN9'),'escape'),'LATIN9') from
> chartest;
>
> His output was:
>
> to_ascii
> ----------
>  a
>
> but i'm getting:
>
>  to_ascii
> ----------
>  \341
>
> What am I doing wrong? How to_ascii function should be used?

What answer do you get to the following two SQL statements:

SHOW server_encoding;
SHOW client_encoding;

Maybe that will help to understand.

Yours,
Laurenz Albe

Re: problem with to_ascii() function in version 8.3.3

From
Pavel Arnošt
Date:
> What answer do you get to the following two SQL statements:
>
> SHOW server_encoding;
> SHOW client_encoding;
>
> Maybe that will help to understand.

Hi,

both commands shows "UTF8". Changing client encoding with "\encoding
LATIN9" does not have any effect on to_ascii command (I don't know if
it should have).

regards
Pavel

Re: problem with to_ascii() function in version 8.3.3

From
"Albe Laurenz"
Date:
Pavel Arnošt wrote:
>>> insert into chartest (c) values ('á');
>>> select to_ascii(encode(convert_to(c,'LATIN9'),'escape'),'LATIN9') from chartest;
>>>  to_ascii
>>> ----------
>>>  \341
>>
>> What answer do you get to the following two SQL statements:
>>
>> SHOW server_encoding;
>> SHOW client_encoding;
>
> both commands shows "UTF8". Changing client encoding with "\encoding
> LATIN9" does not have any effect on to_ascii command (I don't know if
> it should have).

Strange; I have the same settings and it works here.

Could you run the following queries and compare with my results:

test=> select ascii(c) from chartest;
 ascii 
-------
   225
(1 row)

test=> select encode(convert_to(c,'LATIN9'),'hex') from chartest;
 encode 
--------
 e1
(1 row)

test=> select ascii(to_ascii(encode(convert_to(c,'LATIN9'),'escape'),'LATIN9'))  from chartest;
 ascii 
-------
    97
(1 row)

Yours,
Laurenz Albe

Re: problem with to_ascii() function in version 8.3.3

From
Pavel Arnošt
Date:
> Could you run the following queries and compare with my results:
>
> test=> select ascii(c) from chartest;
>  ascii
> -------
>    225
> (1 row)
>
> test=> select encode(convert_to(c,'LATIN9'),'hex') from chartest;
>  encode
> --------
>  e1
> (1 row)
>
> test=> select ascii(to_ascii(encode(convert_to(c,'LATIN9'),'escape'),'LATIN9'))  from chartest;
>  ascii
> -------
>     97
> (1 row)

It gives me:

 ascii
-------
   225

 encode
--------
 e1

 ascii
-------
    92

So the last command have different output. Strange.

regards
Pavel