BF [ 1824260 ] TRUNC function not working like in Oracle
This commit is contained in:
parent
8986763ffc
commit
39f6d4cf50
|
@ -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);
|
||||
|
|
|
@ -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
|
|
@ -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;
|
Loading…
Reference in New Issue