Perform two actions on the same Trigger in Postgres

Asked

Viewed 108 times

1

I’m having trouble with Trigger where:

  • The table itens_compra_fornecedor through the column valor_compra calculates the resale price of the column valor_revendaon the table produto that has no effect.
  • And also Trigger’s other action is to update the field data_relatorio_compra table relatorio_compra_fornecedor that does not return the date.

Diagram

inserir a descrição da imagem aqui

Trigger to calculate the resale value is that

create or replace function preco_revenda()
    returns trigger as $$              
        begin                   
        new.valor_revenda := (select sum (itens_compra_fornecedor.valor_compra + (itens_compra_fornecedor.valor_compra * 0.5)) 
        from produto where produto.cd_itens_compra_fornecedor = new.cd_itens_compra_fornecedor);

        update relatorio_compra_fornecedor set data_compra_fornecedor = now()                         
        from relatorio_compra_fornecedor where relatorio_compra_fornecedor.cd_relatorio_compra_fornecedor = new.cd_relatorio_compra_fornecedor;
        
        return new;
        end                    
            $$ language plpgsql;

create trigger preco_revenda
before insert or update on produto              
for each row                       
execute procedure preco_revenda();
  • If you want me to update the picture to show the whole bank let me know, only I can ask for help to other Rigger if you need, helping me to fire this report I can use the code to also fire other triggers of product sales report and return report.

  • Please just don’t close my question, because I really need help in making my web system for college stuff.

  • Can’t you do both actions on the same trigger? Is there another reason why it’s two triggers?

  • @anonimo I thought I could perform two actions on the same trigger.

  • Then put on your trigger an update of the supplier.

  • @anonymity update relatorio_compra_fornecedor set data_compra_fornecedor = now() from relatorio_compra_fornecedor where relatorio_compra_fornecedor.cd_relatorio_compra_fornecedor = new.cd_relatorio_compra_fornecedor;?

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.