* previous version of addDays cause infinite loop
This commit is contained in:
parent
73cffd61c0
commit
c208946175
|
@ -22,13 +22,18 @@
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION addDays(datetime TIMESTAMP WITH TIME ZONE, days Numeric)
|
CREATE OR REPLACE FUNCTION addDays(datetime TIMESTAMP WITH TIME ZONE, days Numeric)
|
||||||
RETURNS DATE AS $$
|
RETURNS DATE AS $$
|
||||||
|
declare duration varchar;
|
||||||
BEGIN
|
BEGIN
|
||||||
RETURN CAST(datetime AS DATE) + days;
|
if datetime is null or days is null then
|
||||||
|
return null;
|
||||||
|
end if;
|
||||||
|
duration = days || ' day';
|
||||||
|
return cast(date_trunc('day',datetime) + cast(duration as interval) as date);
|
||||||
END;
|
END;
|
||||||
$$ LANGUAGE plpgsql;
|
$$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION subtractdays (day TIMESTAMP WITH TIME ZONE, days NUMERIC)
|
CREATE OR REPLACE FUNCTION subtractdays (day TIMESTAMP WITH TIME ZONE, days NUMERIC)
|
||||||
RETURNS TIMESTAMP WITH TIME ZONE AS $$
|
RETURNS DATE AS $$
|
||||||
BEGIN
|
BEGIN
|
||||||
RETURN addDays(day,(days * -1));
|
RETURN addDays(day,(days * -1));
|
||||||
END;
|
END;
|
||||||
|
|
Loading…
Reference in New Issue