diff --git a/db/postgresql/functions/trunc.sql b/db/postgresql/functions/trunc.sql index 891e8d0319..ae5c689d2a 100644 --- a/db/postgresql/functions/trunc.sql +++ b/db/postgresql/functions/trunc.sql @@ -33,7 +33,7 @@ BEGIN END; $$ 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 $$ BEGIN IF format = 'Q' THEN @@ -52,6 +52,13 @@ BEGIN 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; + CREATE OR REPLACE FUNCTION trunc(i INTERVAL) RETURNS INTEGER AS $$ BEGIN diff --git a/migration/i9/oracle/202211180700_IDEMPIERE-5481.sql b/migration/i9/oracle/202211180700_IDEMPIERE-5481.sql new file mode 100644 index 0000000000..d5927aa657 --- /dev/null +++ b/migration/i9/oracle/202211180700_IDEMPIERE-5481.sql @@ -0,0 +1,6 @@ +SET SQLBLANKLINES ON +SET DEFINE OFF + +SELECT register_migration_script('202211180700_IDEMPIERE-5481.sql') FROM dual; + +-- PostgreSQL Only diff --git a/migration/i9/postgresql/202211180700_IDEMPIERE-5481.sql b/migration/i9/postgresql/202211180700_IDEMPIERE-5481.sql new file mode 100644 index 0000000000..153e8077c1 --- /dev/null +++ b/migration/i9/postgresql/202211180700_IDEMPIERE-5481.sql @@ -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;