I'm running this code:
CREATE OR REPLACE FUNCTION trg_orders_check()
RETURNS trigger
LANGUAGE plpgsql AS
$func$
BEGIN
IF NEW.type = 'prescription' AND NEW.prescription_id IS NULL THEN
RAISE EXCEPTION 'Must include prescription_id';
ELSE IF NEW.TYPE = 'item' AND NEW.item_id IS NULL THEN
RAISE EXCEPTION 'Must include item_id';
ELSE
RAISE EXCEPTION 'Type must be either prescription or item';
END IF;
END
$func$;
I get the error:
syntax error at end of input
What's wrong with it?