Pensei em fazer daquela forma porque se não vou ter que fazer 1 select para
cada campo. Estou certo?
Da forma que você colocou, iria ficar assim:
declare
vnome varchar(50);
vdoc varchar(14);
begin
select cli_nom into vnome from erp_cliente where cli_cod = new.cli_cod;
select cli_num_cpf_cnpj into vdoc from erp_cliente where cli_cod =
new.cli_cod;
if found then
new.ven_nom_cli := vnome
new.ven_num_cpf_cnpj := vdoc
end if;
return new;
end;
Eu não perderia performance ?
Rudinei Dias-3 wrote:
>
> Talvez se mudares a lógica da tua trigger...
> da uma olhada nessa
>
>
> CREATE OR REPLACE FUNCTION fnpessoa_nacionalidade_upd()
> RETURNS "trigger" AS
> $BODY$
> DECLARE
> vNACIONALIDADE varchar(100);
> BEGIN
> if new.spas_id is not null then
> select spas_nacion into vNACIONALIDADE
> from sie_paises
> where spas_id = new.spas_id;
> else
> select spas_nacion into vNACIONALIDADE
> from sie_paises
> where spas_id = old.spas_id;
> end if;
>
> if found then
> new.nacionalidade := vNACIONALIDADE;
> end if;
>
> RETURN new;
> END; $BODY$
> LANGUAGE 'plpgsql' VOLATILE;
>
> onde testo se o campo recebido new.spas_id para null e depois então faço o
> select na tabela para atualizar (if found) o new.nacionalidade caso
> encontrado registro na tab.
>
>
> 2008/7/22 Glauber Almeida <[EMAIL PROTECTED]>:
>
>>
>> Pois é.
>>
>> Foi a primeira coisa que conferir na tabela de vendas e clientes.
>>
>> Tabela de venda erp_venda
>> ven_nom_cli varchar(50)
>>
>> Tabela de clientes erp_cliente
>> cli_nom varchar(50)
>>
>>
>> Isso que é foda, mas não sei se tenho que declarar esses campos ou se o
>> tipo
>> rowtype já pega o tipo das colunas selecionadas da própria tabela.
>>
>>
>>
>> Rudinei Dias-3 wrote:
>> >
>> > Erro: invalid input syntax for integer: "ERLON PAULO ANDRADE"
>> > CONTEXT: PL/pgSQL function "fun_tri_erp_venda_ins" line 11 at
>> SQL
>> > statement
>> >
>> > Glauber,
>> >
>> > pelo erro que o postgres esta retornando, parece que o tipo do campo
>> > ven_nom_cli não corresponde a rscliente.cli_nom.
>> >
>> > Rudinei Dias
>> >
>> >
>> >
>> > 2008/7/22 Glauber Almeida <[EMAIL PROTECTED]>:
>> >
>> >>
>> >> Bom pessoal, estou com um problema em uma trigger e não consigo achar
>> o
>> >> que
>> >> esta errado.
>> >>
>> >> Funcionalidade:
>> >> Na inclusão da venda deve selecionar o cliente na tabela de clientes e
>> >> duplicar os dados (nome do cliente, número do cpf/cnpj) na tabela de
>> >> venda.
>> >>
>> >> Trigger: tri_erp_venda_ins
>> >> Type: before
>> >> For each: Row
>> >> On event: Insert
>> >>
>> >> $body$
>> >> declare
>> >> rscliente erp_cliente%rowtype;
>> >>
>> >> begin
>> >> select cli_cod, cli_nom, cli_num_cpf_cnpj into rscliente from
>> >> erp_cliente
>> >> where cli_cod = new.cli_cod;
>> >> if not rscliente.cli_cod is null then
>> >> new.ven_nom_cli := rscliente.cli_nom;
>> >> new.ven_num_cpf_cnpj := rscliente.cli_num_cpf_cnpj;
>> >> else
>> >> new.cli_cod:=1;
>> >> new.ven_nom_cli := 'CONSUMIDOR FINAL';
>> >> new.ven_num_cpf_cnpj := '1234567890';
>> >> end if;
>> >> end;
>> >>
>> >> end;
>> >> $body$
>> >>
>> >>
>> >> Erro: invalid input syntax for integer: "ERLON PAULO ANDRADE"
>> >> CONTEXT: PL/pgSQL function "fun_tri_erp_venda_ins" line 11 at
>> SQL
>> >> statement
>> >>
>> >> Ao inserir na tabela de vendas um código de cliente existente na
>> tabela
>> >> de
>> >> cliente esta ocorrendo o erro acima.
>> >>
>> >>
>> >>
>> >> --
>> >> View this message in context:
>> >> http://www.nabble.com/Erro-em-trigger-tp18597325p18597325.html
>> >> Sent from the PostgreSQL - Brasil mailing list archive at Nabble.com.
>> >>
>> >> _______________________________________________
>> >> 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
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Erro-em-trigger-tp18597325p18597612.html
>> Sent from the PostgreSQL - Brasil mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> 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
>
>
--
View this message in context:
http://www.nabble.com/Erro-em-trigger-tp18597325p18598103.html
Sent from the PostgreSQL - Brasil mailing list archive at Nabble.com.
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral