2009/9/3 Tiago Adami <[email protected]>:
> Bom dia a todos.
>
> Tenho um banco na versão 8.3 do PostgreSQL encoding UTF8. Estou tentando
> executar a função TO_ASCII e então recebo a informação de que a conversão
> não é suportada:
>
> ERROR:  encoding conversion from UTF8 to ASCII not supported
>
> Já tentei usar as funções CONVERT e CONVERT_TO, mas os dados retornados são
> do tipo bytea e não servem. Também tentei usar o parâmetro 'LATIN1' e o
> resultado não é compatível com a realidade.
>
> Exemplos:
>
> SELECT TO_ASCII( 'À AÇÃO' )
> Resultado:
> ERROR:  encoding conversion from UTF8 to ASCII not supported
>
> SELECT TO_ASCII( 'À AÇÃO', 'LATIN1' )
> Resultado:
> ------------------
> to_ascii
> text
> ------------------
> "A  AA A O"
>
> Há como fazer esta conversão em um banco UTF8?
>


Do manual:
"to_ascii(string text [, encoding text]) - Convert string to ASCII
from another encoding (only supports conversion from LATIN1, LATIN2,
LATIN9, and WIN1250 encodings) "
http://www.postgresql.org/docs/current/interactive/functions-string.html

Acentuação pode ser bastante complexa dependendo da língua (o que é um
caracter acentuado em hangul ou em chinês?).
O que utilizo é uma função que chama a built-in translate.

CREATE FUNCTION sem_acento(text) RETURNS text AS $$
    SELECT 
translate($1,'ÀÁÂÃÄÅĀĂĄÈÉÊËĒĔĖĘĚÌÍÎÏĨĪĮİÒÓÔÕÖØŌŎŐÙÚÛÜŨŪŬŮŰŲàáâãäåāăąèéêëēĕėęěìíîïĩīĭįòóôõöøōŏőùúûüũūŭůųÇçÑñÝýÿĆćĈĉĊċČčĎďĐđĜĝĞğĠġĢģĤĥĦħ',

'AAAAAAAAAEEEEEEEEEIIIIIIIIOOOOOOOOOUUUUUUUUUUaaaaaaaaaeeeeeeeeeiiiiiiiiooooooooouuuuuuuuuCcNnYyyCcCcCcCcDdDdGgGgGgGgHhHh');
$$
LANGUAGE sql IMMUTABLE STRICT;

Modifique as strings de modo a contemplar todos os caracteres que
deseja converter para seu correspondente não-acentuado.

Osvaldo
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Responder a