Em 15-02-2013 17:05, Deliane Andrade escreveu:
> Boa tarde!
> Tenho uma  function para fonetizar nomes na minha base de dados.
> Ela foi escrita na versão 8.4.5 e agora migramos para a 9.2 e está
> ocorrendo o seguinte erro:
>
> ERRO:  matriz mal formada:
> "{".","/","\\\\","$","?",":","\\"",";",",","-","_","&","!","~","`","(",")","Ý","=","+",">","<"}"
> CONTEXT:  PL/pgSQL function corporativo.func_fonetizar(text,boolean)
> line 43 at atribuição
>
> Executo o seguinte comando :
> select * from corporativo.func_fonetizar ('DELIANE ANDRADE',FALSE);
>
> Alguém sabe o que pode estar ocorrendo?

Está na linha:
vCaracteresEspeciais    := 
'{".","/","\\\\","$","?",":","\\"",";",",","-","_","&","!","~","`","(",")","Ý","=","+",">","<"}';

O escape de caracteres está fora do padrão ANSI-SQL.
Opção 1: Verifique o link [1]
Opção 2: Ajuste a configuração standard_conforming_strings para off, 
explicação em [2]

O uso de escapes de acordo com o padrão ANSI-SQL foi reforçado nas 
versões mais recentes do PostgreSQL.


[1] 
http://www.postgresql.org/docs/9.2/interactive/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS
[2] 
http://www.postgresql.org/docs/9.2/interactive/runtime-config-compatible.html#GUC-STANDARD-CONFORMING-STRINGS

[]s

__________________________________
Flavio Henrique A. Gurgel
Líder de Projetos Especiais
Consultoria, Projetos & Treinamentos 4LINUX
Tel1: +55-11.2125-4747 ou 2125-4748
www.4linux.com.br
email: [email protected]
______________________________
FREE SOFTWARE SOLUTIONS


>
>
> Segue a function :
>
> ---------------------------------------------------------------------------------------------------------
>
> CREATE OR REPLACE FUNCTION corporativo.func_fonetizar (
>    text,
>    boolean
> )
> RETURNS text AS
> $body$
> declare
>    bConsulta alias for $2;
>
>    tStr text;
>    tParticula text;
>    tFonetizado text;
>    bFonetizar boolean;
>    tAux text;
>    i integer;
>    iCont integer;
>
>    vAcentos varchar[];
>    vAcentosSub varchar[];
>    vCaracteresEspeciais varchar[];
>    vCaracteresEspeciaisSub varchar[];
>    vPreposicoes varchar[];
>    vAlgRomano varchar[];
>    vNumero varchar[];
>    vAlgarismo varchar[];
>    vAlgarismoExtenso varchar[];
>    vLetras varchar[];
> begin
>    tStr := upper($1);
>    tStr := trim(both ' ' from tStr);
>
>    /*ELIMINAR ACENTOS*/
>    vAcentos    :=
> '{"á","Á","à","À","â","Â","ã","Ã","é","É","è","È","ê","Ê","í","Í","ì","Ì","î","Î","ó","Ó","ò","Ò","ô","Ô","õ","Õ","ú","Ú","ù","Ù","û","Û","ü","Ü","ç","Ç"}';
>    vAcentosSub :=
> '{"A","A","A","A","A","A","A","A","E","E","E","E","E","E","I","I","I","I","I","I","O","O","O","O","O","O","O","O","U","U","U","U","U","U","U","U","S","S"}';
>
>    for i in 1..38 /*array_length(vAcentos)*/ loop
>      select replace(tStr, vAcentos[i], vAcentosSub[i]) into tStr;
>    end loop;
>
>
>    /*********************************************/
>    if tStr = ' H ' then
>      tStr := ' AGA ';
>    end if;
>
>    /*ELIMINAR CARACTERES ESPECIAIS*/
>    /*verificar*/
>    vCaracteresEspeciais    :=
> '{".","/","\\\\","$","?",":","\\"",";",",","-","_","&","!","~","`","(",")","Ý","=","+",">","<"}';
>    vCaracteresEspeciaisSub := '{""," "," "," "," "," "," "," "," "," ","
> "," "," "," "," "," "," "," "," "," "," "," "}';
>
>    for i in 1..20 /*length(vCaracteresEspeciais)*/ loop
>      select replace(tStr, vCaracteresEspeciais[i], '
> '/*vCaracteresEspeciaisSub[i]*/) into tStr;
>    end loop;
>
>    /*ELIMINAR ESPACOS EM BRANCO MAIOR QUE 1*/
>    for i in 1..2 loop
>      select replace(tStr, '  ', ' ') into tStr;
>    end loop;
>
>    /*ELIMINAR PALAVRAS ESPECIAIS*/
>    select replace(tStr, ' LTDA ', ' ') into tStr;
>
>    /*ELIMINAR PREPOSICOES*/
>    vPreposicoes := '{" DE "," DA "," DAS "," DO "," DOS "," AS "," OS
> "," AO "," AOS "," NA "," NAS "," NO "," NOS "," COM "}';
>
>    for i in 1..14 /*length(vPreposicoes)*/ loop
>      select replace(tStr, vPreposicoes[i], ' ') into tStr;
>    end loop;
>
>    /*CONVERTE ALGARISMO ROMANO PARA NUMERO*/
>    vAlgRomano = '{" X "," IX "," VIII "," VII "," VI "," V "," IV ","
> III "," II "," I "}';
>    vNumero    = '{" 10 "," 9 "," 8 "," 7 "," 6 "," 5 "," 4 "," 3 "," 2
> "," 1 "}';
>
>    for i in 1..10 /*length(vAlgRomano)*/ loop
>      select replace(tStr, vAlgRomano[i], vNumero[i]) into tStr;
>    end loop;
>
>    /*CONVERTE NUMERO PARA LITERAL*/
>    vAlgarismo        = '{"0","1","2","3","4","5","6","7","8","9"}';
>    vAlgarismoExtenso =
> '{"ZERO","UM","DOIS","TRES","QUATRO","CINCO","SEIS","SETE","OITO","NOVE"}';
>
>    for i in 1..10 /*length(vAlgarismo)*/ loop
>      select replace(tStr, vAlgarismo[i], vAlgarismoExtenso[i]) into tStr;
>    end loop;
>
>    /*********************************************/
>    /*ELIMINAR PREPOSICOES E ARTIGOS*/
>    vLetras = '{" A "," B "," C "," D "," E "," F "," G "," H "," I "," J
> "," K "," L "," M "," N "," O "," P "," Q "," R "," S "," T "," U "," V
> "," X "," Z "," W "," Y "}';
>
>    for i in 1..26 /*length(vLetras)*/ loop
>      select replace(tStr, vLetras[i], ' ') into tStr;
>    end loop;
>
>    tStr := trim(both ' ' from tStr);
>    tParticula := '';
>    tFonetizado := '';
>    for iCont in 1..length(tStr) + 1 loop
>      if iCont < length(tStr) + 1 then
>        if substring(tStr,iCont,1) <> ' ' then
>          tParticula := tParticula || substring(tStr,iCont,1);
>          bFonetizar := false;
>        else
>          bFonetizar := true;
>        end if;
>      else
>        bFonetizar := true;
>      end if;
>
>      if bFonetizar then
>        tParticula := corporativo.func_fonetizar_particula(tParticula);
>
>        tFonetizado := tFonetizado || ' ' || tParticula;
>        tParticula := '';
>      end if;
>    end loop;
>
>    tFonetizado := trim(both ' ' from tFonetizado);
>
>    /*PREPARA A STRING PARA UM LIKE*/
>    if bConsulta then
>      tAux := '%';
>
>      for i in 1..length(tFonetizado) loop
>        if substring(tFonetizado,i,1) = ' ' then
>          tAux := tAux || '% %';
>        else
>          tAux := tAux || substring(tFonetizado,i,1);
>        end if;
>      end loop;
>
>      if substring(tFonetizado,Length(tFonetizado),1) <> '%' then
>        tAux := tAux || '%';
>      end if;
>
>      tFonetizado := tAux;
>    end if;
>
>    return tFonetizado;
> end;
> $body$
> LANGUAGE 'plpgsql'
> VOLATILE
> RETURNS NULL ON NULL INPUT
> SECURITY INVOKER
> COST 100;
>
>
> _______________________________________________
> pgbr-geral mailing list
> [email protected]
> https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral
>
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Responder a