|
CREATE FUNCTION NEXT_DAY(DATE,CHAR)
RETURNS DATE AS '
DECLARE
ret DATE;
BEGIN
IF $2 = ''日'' THEN
SELECT next_day($1,0) INTO ret;
END IF;
IF $2 = ''月'' THEN
SELECT next_day($1,1) INTO ret;
END IF;
IF $2 = ''火'' THEN
SELECT next_day($1,2) INTO ret;
END IF;
IF $2 = ''水'' THEN
SELECT next_day($1,3) INTO ret;
END IF;
IF $2 = ''木'' THEN
SELECT next_day($1,4) INTO ret;
END IF;
IF $2 = ''金'' THEN
SELECT next_day($1,5) INTO ret;
END IF;
IF $2 = ''土'' THEN
SELECT next_day($1,6) INTO ret;
END IF;
RETURN RET;
END;
' LANGUAGE 'plpgsql';
CREATE FUNCTION NEXT_DAY(DATE,INT)
RETURNS DATE AS '
DECLARE
c ALIAS FOR $1;
p NUMERIC;
q ALIAS FOR $2;
ret DATE;
BEGIN
SELECT date_part(''dow'', c ) INTO p;
IF (q-p)>0 THEN
ret = c + (q-p)||'' days'';
ELSE
ret = c + ((q-p)+7)||'' days'';
END IF;
RETURN RET;
END;
' LANGUAGE 'plpgsql';
|
|