Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE OR REPLACE FUNCTION insert_mp(
- _name VARCHAR,
- _description VARCHAR,
- _abbreviation VARCHAR,
- _price_without_taxes double precision,
- _um_nombre VARCHAR
- ) RETURNS INTEGER AS $$
- DECLARE
- um_id INTEGER;
- BEGIN
- /* poner varios if else por cada foreign key */
- IF EXISTS(select 1 from measure_units where abbreviation=_um_nombre) THEN
- um_id := (select measure_unit_id from measure_units where abbreviation=_um_nombre);
- ELSE
- RETURN 1;
- END IF;
- INSERT INTO material_types(name, description, abbreviation, price_without_taxes, measure_unit_id)
- VALUES (_name, _description, _abbreviation, _price_without_taxes, um_id);
- RETURN 0;
- END
- $$ language plpgsql;
- --select insert_mp('bbb', 'ccc', 'ddd', 15.4, 'kg');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement