BF [ 1824260 ] TRUNC function not working like in Oracle

This commit is contained in:
teo_sarca 2007-11-02 06:11:31 +00:00
parent 8986763ffc
commit 39f6d4cf50
3 changed files with 41 additions and 2 deletions

View File

@ -31,9 +31,9 @@ RETURNS DATE AS $$
BEGIN
IF format = 'Q' THEN
RETURN CAST(DATE_Trunc('quarter',datetime) as DATE);
ELSIF format = 'Y' THEN
ELSIF format = 'Y' or format = 'YEAR' THEN
RETURN CAST(DATE_Trunc('year',datetime) as DATE);
ELSIF format = 'MM' THEN
ELSIF format = 'MM' or format = 'MONTH' THEN
RETURN CAST(DATE_Trunc('month',datetime) as DATE);
ELSIF format = 'DD' THEN
RETURN CAST(DATE_Trunc('day',datetime) as DATE);

View File

@ -0,0 +1,4 @@
-- BF [ 1824260 ] TRUNC function not working like in Oracle
-- http://sourceforge.net/tracker/?func=detail&atid=879332&aid=1824260&group_id=176962
--
-- Nothing to do for Oracle, this is just a sequence placeholder

View File

@ -0,0 +1,35 @@
-- BF [ 1824260 ] TRUNC function not working like in Oracle
-- http://sourceforge.net/tracker/?func=detail&atid=879332&aid=1824260&group_id=176962
--
CREATE OR REPLACE FUNCTION trunc(datetime TIMESTAMP WITH TIME ZONE)
RETURNS DATE AS $$
BEGIN
RETURN CAST(datetime AS DATE);
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION trunc(datetime TIMESTAMP WITH TIME ZONE, format varchar)
RETURNS DATE AS $$
BEGIN
IF format = 'Q' THEN
RETURN CAST(DATE_Trunc('quarter',datetime) as DATE);
ELSIF format = 'Y' or format = 'YEAR' THEN
RETURN CAST(DATE_Trunc('year',datetime) as DATE);
ELSIF format = 'MM' or format = 'MONTH' THEN
RETURN CAST(DATE_Trunc('month',datetime) as DATE);
ELSIF format = 'DD' THEN
RETURN CAST(DATE_Trunc('day',datetime) as DATE);
ELSIF format = 'DY' THEN
RETURN CAST(DATE_Trunc('day',datetime) as DATE);
ELSE
RETURN CAST(datetime AS DATE);
END IF;
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION trunc(i INTERVAL)
RETURNS INTEGER AS $$
BEGIN
RETURN EXTRACT(DAY FROM i);
END;
$$ LANGUAGE plpgsql;