Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE OR REPLACE FUNCTION insert_mp(
  2.   _name VARCHAR,
  3.   _description VARCHAR,
  4.   _abbreviation VARCHAR,
  5.   _price_without_taxes double precision,
  6.   _um_nombre VARCHAR
  7. ) RETURNS INTEGER AS $$
  8. DECLARE
  9.   um_id INTEGER;
  10. BEGIN
  11.   /* poner varios if else por cada foreign key */
  12.   IF EXISTS(select 1 from measure_units where abbreviation=_um_nombre) THEN
  13.     um_id := (select measure_unit_id from measure_units where abbreviation=_um_nombre);
  14.    ELSE
  15.     RETURN 1;
  16.   END IF;
  17.  
  18.   INSERT INTO material_types(name, description, abbreviation, price_without_taxes, measure_unit_id)
  19.   VALUES (_name, _description, _abbreviation, _price_without_taxes, um_id);
  20.   RETURN 0;
  21. END
  22. $$ language plpgsql;
  23.  
  24. --select insert_mp('bbb', 'ccc', 'ddd', 15.4, 'kg');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement