Guest User

Untitled

a guest
Oct 21st, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. Create type ComprositionPrixod AS (
  2. Id bigint,
  3. Name character varying,
  4. Count bigint,
  5. Price double precision
  6. );
  7.  
  8. CREATE TABLE "Prixod" (
  9. "id" serial NOT NULL,
  10. "Date" timestamp without time zone,
  11. "OrgPostav" character varying,
  12. "NameSklad" character varying,
  13. "Сomposition" ComprositionPrixod[],
  14. "Operator" character varying,
  15. "Total" double precision DEFAULT sum(),
  16. CONSTRAINT Prixod_pk PRIMARY KEY ("id")
  17. ) WITH (
  18. OIDS=FALSE
  19. );
  20.  
  21. select sum(u.price) from unnest(Сomposition) u
  22.  
  23. CREATE OR REPLACE FUNCTION prixod_trigger_func() RETURNS trigger AS $TRIGGER$
  24. BEGIN
  25. NEW."Total" = (select sum(u.price) from unnest(NEW."Сomposition") u);
  26. return NEW;
  27. END;
  28. $TRIGGER$
  29. LANGUAGE plpgsql;
  30.  
  31. CREATE TRIGGER prixod_trigger
  32. BEFORE INSERT OR UPDATE ON "Prixod" FOR EACH ROW
  33. EXECUTE PROCEDURE prixod_trigger_func();.
Add Comment
Please, Sign In to add comment