IDEMPIERE-5481 PostgreSQL: trunc(timestamp,format) missing version for TIMESTAMP WITHOUT TIME ZONE (#1569)

This commit is contained in:
hengsin 2022-11-21 20:56:25 +08:00 committed by GitHub
parent 2ff6378720
commit 222c201d78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 1 deletions

View File

@ -33,7 +33,7 @@ BEGIN
END; END;
$$ LANGUAGE plpgsql IMMUTABLE; $$ LANGUAGE plpgsql IMMUTABLE;
CREATE OR REPLACE FUNCTION trunc(datetime TIMESTAMP WITH TIME ZONE, format varchar) CREATE OR REPLACE FUNCTION trunc(datetime TIMESTAMP WITHOUT TIME ZONE, format varchar)
RETURNS DATE AS $$ RETURNS DATE AS $$
BEGIN BEGIN
IF format = 'Q' THEN IF format = 'Q' THEN
@ -52,6 +52,13 @@ BEGIN
END; END;
$$ LANGUAGE plpgsql IMMUTABLE; $$ LANGUAGE plpgsql IMMUTABLE;
CREATE OR REPLACE FUNCTION trunc(datetime TIMESTAMP WITH TIME ZONE, format varchar)
RETURNS DATE AS $$
BEGIN
RETURN trunc(cast(datetime as timestamp without time zone), format);
END;
$$ LANGUAGE plpgsql IMMUTABLE;
CREATE OR REPLACE FUNCTION trunc(i INTERVAL) CREATE OR REPLACE FUNCTION trunc(i INTERVAL)
RETURNS INTEGER AS $$ RETURNS INTEGER AS $$
BEGIN BEGIN

View File

@ -0,0 +1,6 @@
SET SQLBLANKLINES ON
SET DEFINE OFF
SELECT register_migration_script('202211180700_IDEMPIERE-5481.sql') FROM dual;
-- PostgreSQL Only

View File

@ -0,0 +1,27 @@
SELECT register_migration_script('202211180700_IDEMPIERE-5481.sql') FROM dual;
CREATE OR REPLACE FUNCTION trunc(datetime TIMESTAMP WITHOUT 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 IMMUTABLE;
CREATE OR REPLACE FUNCTION trunc(datetime TIMESTAMP WITH TIME ZONE, format varchar)
RETURNS DATE AS $$
BEGIN
RETURN trunc(cast(datetime as timestamp without time zone), format);
END;
$$ LANGUAGE plpgsql IMMUTABLE;