
DECLARE
	unit text;
	yy int;
	mm int;
BEGIN
	unit := lower(interval_unit);
	IF unit NOT IN ('month', 'year') THEN
		RAISE '"%" is not a valid interval unit', interval_unit
			USING ERRCODE = 'invalid_parameter_value';
	END IF;
	-- If we have decimal point, then we need to find whole month
	-- corresponding to that
	IF (unit = 'year') THEN
		yy := floor(n);
		mm := round((n - yy) * 12);
	ELSIF (unit = 'month') THEN
		yy := 0;
		mm := round(n);
	END IF;
	RETURN concat(yy, ' year ', mm, ' month')::interval;
END;
