CREATE OR REPLACE FUNCTION cenlr_date_est_valide(integer, integer, integer)
RETURNS BOOLEAN AS
$BODY$
DECLARE
jour alias FOR $1;
mois alias FOR $2;
annee alias FOR $3;
var_result BOOLEAN;
BEGIN
IF (mois IN (1,3,5,7,8,10,12) AND jour <=31) THEN
var_result = true;
RETURN var_result;
ELSIF (mois IN (4,6,9,11) AND jour <=30) THEN
var_result = true;
RETURN var_result;
ELSIF ((mois = 2 AND (annee % 4) = 0 AND jour <=29) OR (mois = 2 AND (annee % 4) <> 0 AND jour <=28)) THEN
var_result = true;
RETURN var_result;
ELSE var_result = false;
RETURN var_result;
END IF;
RETURN NULL;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
CREATE OR REPLACE FUNCTION day_name(date)
RETURNS text AS
$BODY$
DECLARE
date_test alias FOR $1;
var_result text;
myrec RECORD;
BEGIN
FOR myrec IN
SELECT CASE extract(isodow FROM date_test)
WHEN 1 then 'lundi'
WHEN 2 THEN 'mardi'
WHEN 3 THEN 'mercredi'
WHEN 4 THEN 'jeudi'
WHEN 5 THEN 'vendredi'
WHEN 6 THEN 'samedi'
WHEN 7 THEN 'dimanche'
END AS jour
LOOP
var_result:=myrec.jour;
END LOOP;
RETURN var_result;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
$> SELECT day_name('2010-02-07');
$> dimanche