Error in Trigger function. How to correct?

Поиск
Список
Период
Сортировка
От Andre Lopes
Тема Error in Trigger function. How to correct?
Дата
Msg-id h2h18f98e681004140603v6c5ad253h2eaf786f5c0306a7@mail.gmail.com
обсуждение исходный текст
Ответы Re: Error in Trigger function. How to correct?  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
Список pgsql-general
Hi,

I have a trigger that runs in my Development machine but not in my Production machine. the code is the following:

[code]
CREATE OR REPLACE FUNCTION "aprtr_geraemail_agcompagamento" ()    
RETURNS trigger AS
$BODY$
   
    DECLARE
    vSUBJECT varchar(500);
    vEMAIL_MSG_BRUTO text;
    vEMAIL_MSG_COMPOSTA text; -- Tem o body do email já preenchido.
    vEMAIL_TO varchar(500);
   
    -- Variaveis de configuração
    vID_EMAIL_MSG varchar(20);
    vEMAIL_FROM varchar(500);
    vMAX_TRIES int4;
   
   
    BEGIN
    -- ## CONFIGURACOES
    vID_EMAIL_MSG := 'ag_com_pag_sucesso'; -- campo id_email_msg
    vEMAIL_FROM := 'adefinir@mail.com';
    vMAX_TRIES := 3; -- Número máximo de vezes que a mensagem vai tentar ser enviada
    -- ##
   
    -- CONDICOES PARA REALIZAR AS TAREFAS
    if     new.id_estado_insercao = 'sucesso'
    and new.id_estado_concordancia_contrato = 'aceite'
    and new.id_estado_concordancia_pagamento = 'aceite'
    and new.id_estado_pagamento = 'pago' then
   
    -- Vou buscar a mensagem de email (ag_com_pag_sucesso)
    select email_subject, email_msg
    from
    aem_hist_mensagens_email
    where
    id_email_msg = vID_EMAIL_MSG
    and dat_fim is null
    into vSUBJECT, vEMAIL_MSG_BRUTO;
   
   
    -- Vou fazer a mensagem de email
    select
    replace(replace(replace(replace(replace(replace(vEMAIL_MSG_BRUTO, '@numero_anuncio@', a.id_anuncio_externo), '@nome_anuncio@', a.n_anuncio), '@idade@', EXTRACT(year from AGE(NOW(), a.dat_nasc))), '@telefone_anuncio@', a.telefone_anuncio), '@orientacao_sexual@', o.n_orientacao), '@cidade@', c.n_cidade) as email_composto,
    a.email as email_to
    -- a.id_anuncio_externo, a.n_anuncio, a.telefone_anuncio, a.dat_nasc,
    -- c.n_cidade, n.n_nacionalidade, o.n_orientacao
    from
    aae_anuncios a
    join aa_cidades c ON a.id_cidade = c.id_cidade
    join ae_nacionalidades n ON a.id_nacionalidade = n.id_nacionalidade
    join ae_orientacao o ON a.id_orientacao = o.id_orientacao
    where id_anuncio_externo = OLD.id_anuncio_externo
    into vEMAIL_MSG_COMPOSTA, vEMAIL_TO;
   
   
    -- Vou inserir na tabela de mensagens de email (atem_emails_envios)
    insert into aem_emails_envios
    (id_email_msg, dat_inserted, max_tries, email_from, email_to, email_subject, email_msg)
    values
    (vID_EMAIL_MSG, now(), vMAX_TRIES, vEMAIL_FROM, vEMAIL_TO, vSUBJECT, vEMAIL_MSG_COMPOSTA);
   
    -- DEBUG
    -- raise notice ' % ', vEMAIL_MSG_COMPOSTA;
    end if;
   
    RETURN NULL;
    END;
$BODY$
    LANGUAGE PLpgSQL
    CALLED ON NULL INPUT
    VOLATILE
    EXTERNAL SECURITY DEFINER;
[/code]

This code works great in my development machine in Windows. When I move this to the production machine gives me this error:


[error]
SQL Error:

ERROR:  function replace(text, unknown, integer) does not exist
LINE 1: select replace(replace(replace(replace(replace(replace( $1 ,...
                                                       ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
QUERY:  select replace(replace(replace(replace(replace(replace( $1 , '@numero_anuncio@', a.id_anuncio_externo), '@nome_anuncio@', a.n_anuncio), '@idade@', EXTRACT(year from AGE(NOW(), a.dat_nasc))), '@telefone_anuncio@', a.telefone_anuncio), '@orientacao_sexual@', o.n_orientacao), '@cidade@', c.n_cidade) as email_composto, a.email as email_to from aae_anuncios a join aa_cidades c ON a.id_cidade = c.id_cidade join ae_nacionalidades n ON a.id_nacionalidade = n.id_nacionalidade join ae_orientacao o ON a.id_orientacao = o.id_orientacao where id_anuncio_externo =  $2
CONTEXT:  PL/pgSQL function "aprtr_geraemail_agcompagamento" line 46 at SQL statement
[/error]

What can I do to correct this? Some clues?


Best Regards.

В списке pgsql-general по дате отправления:

Предыдущее
От: Bill Moran
Дата:
Сообщение: Re: auto vacuum
Следующее
От: "A. Kretschmer"
Дата:
Сообщение: Re: Error in Trigger function. How to correct?