
CREATE OR REPLACE FUNCTION sp_crud_supervision(accion character varying, p_persona_id integer, p_area_id integer)
  RETURNS character varying AS
$BODY$
declare
	id_supervision integer;
begin

	Case accion
		When 'i' then
			Insert Into supervisiones (persona_id, area_id, fecha_supervision, created_at) 
			Values (p_persona_id, p_area_id, now(), now());
			id_supervision := (SELECT currval('supervisiones_id_seq'));
	End Case;
				
	return id_supervision;
	EXCEPTION
	WHEN OTHERS THEN
        id_supervision:=-1;
	return id_supervision;

end;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
