Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions contrib/babelfishpg_common/sql/coerce.sql
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,23 @@ $$ LANGUAGE plpgsql STABLE;
CREATE OR REPLACE FUNCTION sys._trunc_numeric_to_int8(In arg numeric)
RETURNS INT8 AS $$
BEGIN
RETURN CAST(trunc(arg) AS INT8);
RETURN pg_catalog.int8(trunc(arg));
END;
$$ LANGUAGE plpgsql STABLE;

-- numeric -> int4
CREATE OR REPLACE FUNCTION sys._trunc_numeric_to_int4(In arg numeric)
RETURNS INT4 AS $$
BEGIN
RETURN CAST(trunc(arg) AS INT4);
RETURN pg_catalog.int4(trunc(arg));
END;
$$ LANGUAGE plpgsql STABLE;

-- numeric -> int2
CREATE OR REPLACE FUNCTION sys._trunc_numeric_to_int2(In arg numeric)
RETURNS INT2 AS $$
BEGIN
RETURN CAST(trunc(arg) AS INT2);
RETURN pg_catalog.int2(trunc(arg));
END;
$$ LANGUAGE plpgsql STABLE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,24 @@

-- complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "ALTER EXTENSION ""babelfishpg_common"" UPDATE TO '6.2.0'" to load this file. \quit

CREATE OR REPLACE FUNCTION sys._trunc_numeric_to_int8(In arg numeric)
RETURNS INT8 AS $$
BEGIN
RETURN pg_catalog.int8(trunc(arg));
END;
$$ LANGUAGE plpgsql STABLE;

CREATE OR REPLACE FUNCTION sys._trunc_numeric_to_int4(In arg numeric)
RETURNS INT4 AS $$
BEGIN
RETURN pg_catalog.int4(trunc(arg));
END;
$$ LANGUAGE plpgsql STABLE;

CREATE OR REPLACE FUNCTION sys._trunc_numeric_to_int2(In arg numeric)
RETURNS INT2 AS $$
BEGIN
RETURN pg_catalog.int2(trunc(arg));
END;
$$ LANGUAGE plpgsql STABLE;
6 changes: 3 additions & 3 deletions contrib/babelfishpg_tsql/sql/sys_function_helpers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ EXCEPTION

WHEN invalid_text_representation THEN
GET STACKED DIAGNOSTICS v_err_message = MESSAGE_TEXT;
v_err_message := substring(pg_catalog.lower(v_err_message), 'integer\:\s\"(.*)\"');
v_err_message := substring(pg_catalog.lower(v_err_message) FROM 'integer\:\s\"(.*)\"' :: TEXT);

RAISE USING MESSAGE := pg_catalog.format('Error while trying to convert "%s" value to SMALLINT (or INTEGER) data type.',
v_err_message),
Expand Down Expand Up @@ -545,7 +545,7 @@ EXCEPTION

WHEN invalid_text_representation THEN
GET STACKED DIAGNOSTICS v_err_message = MESSAGE_TEXT;
v_err_message := substring(pg_catalog.lower(v_err_message), 'integer\:\s\"(.*)\"');
v_err_message := substring(pg_catalog.lower(v_err_message) FROM 'integer\:\s\"(.*)\"' :: TEXT);

RAISE USING MESSAGE := pg_catalog.format('Error while trying to convert "%s" value to SMALLINT data type.',
v_err_message),
Expand Down Expand Up @@ -10984,7 +10984,7 @@ BEGIN
END IF;

IF (pg_catalog.lower(p_datatype) LIKE '%varchar%(%' OR pg_catalog.lower(p_datatype) LIKE '%char%(%') THEN
v_varchar_length := substring(p_datatype COLLATE "C" FROM '\(([0-9]+|MAX)\)');
v_varchar_length := substring(p_datatype COLLATE "C" FROM '\(([0-9]+|MAX)\)' :: TEXT);
IF (v_varchar_length IS NOT NULL AND v_varchar_length <> 'MAX' AND char_length(v_result) > v_varchar_length::SMALLINT) THEN
RAISE USING MESSAGE := pg_catalog.format('There is insufficient result space to convert a money value to varchar.'),
DETAIL := 'The converted money value exceeds the specified varchar length.',
Expand Down
6 changes: 3 additions & 3 deletions contrib/babelfishpg_tsql/sql/sys_functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5140,17 +5140,17 @@ BEGIN
RAISE EXCEPTION 'The datepart ''weekday'' is not supported by date function datetrunc for data type ''%''.', date_arg_datatype;
ELSIF date_arg_datatype = 'date'::regtype AND datepart IN ('hour', 'minute', 'second', 'millisecond', 'microsecond') THEN
RAISE EXCEPTION 'The datepart ''%'' is not supported by date function datetrunc for data type ''date''.', datepart;
ELSIF date_arg_datatype = 'datetime'::regtype AND datepart IN ('microsecond') THEN
ELSIF date_arg_datatype = 'sys.datetime'::regtype AND datepart IN ('microsecond') THEN
RAISE EXCEPTION 'The datepart ''%'' is not supported by date function datetrunc for data type ''datetime''.', datepart;
ELSIF date_arg_datatype = 'smalldatetime'::regtype AND datepart IN ('millisecond', 'microsecond') THEN
ELSIF date_arg_datatype = 'sys.smalldatetime'::regtype AND datepart IN ('millisecond', 'microsecond') THEN
RAISE EXCEPTION 'The datepart ''%'' is not supported by date function datetrunc for data type ''smalldatetime''.', datepart;
ELSIF date_arg_datatype = 'time'::regtype THEN
IF datepart IN ('year', 'quarter', 'month', 'doy', 'day', 'week', 'tsql_week') THEN
RAISE EXCEPTION 'The datepart ''%'' is not supported by date function datetrunc for data type ''time''.', datepart;
END IF;
-- Limitation in determining if the specified fractional scale (if provided any) for time datatype is
-- insufficient to support provided datepart (millisecond, microsecond) value
ELSIF date_arg_datatype IN ('datetime2'::regtype, 'datetimeoffset'::regtype) THEN
ELSIF date_arg_datatype IN ('sys.datetime2'::regtype, 'sys.datetimeoffset'::regtype) THEN
-- Limitation in determining if the specified fractional scale (if provided any) for the above datatype is
-- insufficient to support for provided datepart (millisecond, microsecond) value
END IF;
Expand Down
Loading
Loading