nantunes

Ficha 11 ex2

May 6th, 2021
530
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE OR REPLACE FUNCTION sumary_temp() returns TRIGGER
  2. language plpgsql
  3. AS $$
  4. BEGIN
  5.     DELETE FROM temp;
  6.     INSERT INTO temp (col1, col2, message)
  7.         (SELECT  SUM(preco), COUNT(*), genero
  8.            FROM livros
  9.           GROUP BY genero);  
  10.          
  11.     RETURN NULL; -- se for chamado num trigger de statemetn vai dar null na mesma
  12. END;
  13. $$;
  14.  
  15.  
  16. CREATE TRIGGER actualiza_temp
  17.  after INSERT OR DELETE OR UPDATE OF genero, preco ON livros
  18.  -- nao faz sentido -- for each row
  19. EXECUTE PROCEDURE sumary_temp();
RAW Paste Data