Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 28ceea79

Von Moritz Bunkus vor fast 8 Jahren hinzugefügt

  • ID 28ceea79f873b8cdc0ef2e14102ad659bd21bb09
  • Vorgänger b3c6dbe1
  • Nachfolger be096dae

Artikelpreishistorie: Fix für NULL-Behandlung im Trigger

Unterschiede anzeigen:

sql/Pg-upgrade2/add_parts_price_history2.sql
1
-- @tag: add_parts_price_history2
2
-- @description: Korrigierte Triggerfunktion für Entwicklung der Stammdatenpreise
3
-- @depends: add_parts_price_history
4
CREATE OR REPLACE FUNCTION add_parts_price_history_entry() RETURNS "trigger" AS $$
5
  BEGIN
6
    IF      (TG_OP = 'UPDATE')
7
        AND ((OLD.lastcost  IS NULL AND NEW.lastcost  IS NULL) OR (OLD.lastcost  = NEW.lastcost))
8
        AND ((OLD.listprice IS NULL AND NEW.listprice IS NULL) OR (OLD.listprice = NEW.listprice))
9
        AND ((OLD.sellprice IS NULL AND NEW.sellprice IS NULL) OR (OLD.sellprice = NEW.sellprice)) THEN
10
      RETURN NEW;
11
    END IF;
12

  
13
    INSERT INTO parts_price_history (part_id, lastcost, listprice, sellprice, valid_from)
14
    VALUES (NEW.id, NEW.lastcost, NEW.listprice, NEW.sellprice, now());
15

  
16
    RETURN NEW;
17
  END;
18
$$ LANGUAGE plpgsql;

Auch abrufbar als: Unified diff