Skip to content

Address issues with arithmetic, mathematical functions for money/smallmoney #3797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 27 commits into
base: BABEL_5_X_DEV
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
464d572
Merge changes from upstream
ayushdsh May 28, 2025
620f747
smallmoney/money issue; commit for generating PR
ayushdsh May 30, 2025
f2ee215
fixing functions
ayushdsh May 30, 2025
af4e156
Handling overflow and incorrect outputs in case of certain money and …
ayushdsh May 31, 2025
8f54006
Handling overflow and incorrect outputs in case of certain money and …
ayushdsh May 31, 2025
776c6f9
Handling overflow and incorrect outputs in case of certain money and …
ayushdsh May 31, 2025
c27ba50
Handling overflow and incorrect outputs in case of certain money and …
ayushdsh May 31, 2025
dc7e68a
Handling overflow and incorrect outputs in case of certain money and …
ayushdsh May 31, 2025
6f2024b
Handling overflow and incorrect outputs in case of certain money and …
ayushdsh May 31, 2025
5a1ea61
Handling overflow and incorrect outputs in case of certain money and …
ayushdsh Jun 1, 2025
41282ef
Handling overflow and incorrect outputs in case of certain money and …
ayushdsh Jun 1, 2025
32ac4b0
Handling overflow and incorrect outputs in case of certain money and …
ayushdsh Jun 1, 2025
113dcb9
Handling overflow and incorrect outputs in case of certain money and …
ayushdsh Jun 1, 2025
521e2c1
Handling overflow and incorrect outputs in case of certain money and …
ayushdsh Jun 1, 2025
dd36400
Handling overflow and incorrect outputs in case of certain money and …
ayushdsh Jun 1, 2025
f7ff133
Handling overflow and incorrect outputs in case of certain money and …
ayushdsh Jun 1, 2025
a4bd9e3
Handling overflow and incorrect outputs in case of certain money and …
ayushdsh Jun 6, 2025
761d7d3
Handling overflow and incorrect outputs in case of certain money and …
ayushdsh Jun 6, 2025
ce63910
Handling overflow and incorrect outputs in case of certain money and …
ayushdsh Jun 6, 2025
3dd66da
Handling overflow and incorrect outputs in case of certain money and …
ayushdsh Jun 6, 2025
ca099e2
rectified expected dependency file
ayushdsh Jun 6, 2025
a5248b2
Handling overflow and incorrect outputs in case of certain money and …
ayushdsh Jun 9, 2025
8a30290
Handling overflow and incorrect outputs in case of certain money and …
ayushdsh Jun 9, 2025
89f6866
Handling overflow and incorrect outputs in case of certain money and …
ayushdsh Jun 9, 2025
1f7d945
Handling overflow and incorrect outputs in case of certain money and …
ayushdsh Jun 9, 2025
8decac2
Handling overflow and incorrect outputs in case of certain money and …
ayushdsh Jun 9, 2025
6fcd26b
Handling overflow and incorrect outputs in case of certain money and …
ayushdsh Jun 9, 2025
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test/JDBC/target/maven-status/*
test/JDBC/target/surefire-reports/*
test/JDBC/target/test-classes/*

contrib/babelfishpg_common/sql/babelfishpg_common--[0-9].[0-9].[0-9]--[0-9].[0-9].[0-9].sql
contrib/babelfishpg_common/sql/babelfishpg_common--[0-9]*.[0-9]*.[0-9]*--[0-9]*.[0-9]*.[0-9]*.sql
contrib/babelfishpg_common/sql/babelfishpg_common--[0-9].[0-9].[0-9].sql
contrib/babelfishpg_common/src/geo_parser.c
contrib/babelfishpg_common/src/geo_scan.c
Expand Down
97 changes: 97 additions & 0 deletions contrib/babelfishpg_common/sql/bit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -504,3 +504,100 @@ WITH FUNCTION sys.varchar2bit(sys.VARCHAR) AS IMPLICIT;

CREATE CAST (bool AS sys.BIT)
WITHOUT FUNCTION AS IMPLICIT;

CREATE FUNCTION sys.bitsmallmoneypl(sys.BIT, sys.SMALLMONEY)
RETURNS sys.SMALLMONEY
AS $$
BEGIN
IF $1 = 0 THEN
RETURN (SELECT sys.int4fixeddecimalpl(0, $2));
ELSE
RETURN (SELECT sys.int4fixeddecimalpl(1, $2));
END IF;
END;
$$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION sys.bitsmallmoneymi(sys.BIT, sys.SMALLMONEY)
RETURNS sys.SMALLMONEY
AS $$
BEGIN
IF $1 = 0 THEN
RETURN (SELECT sys.int4fixeddecimalmi(0, $2));
ELSE
RETURN (SELECT sys.int4fixeddecimalmi(1, $2));
END IF;
END;
$$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE;

CREATE OPERATOR sys.+ (
LEFTARG = sys.BIT,
RIGHTARG = sys.SMALLMONEY,
COMMUTATOR = +,
PROCEDURE = bitsmallmoneypl
);

CREATE OPERATOR sys.- (
LEFTARG = sys.BIT,
RIGHTARG = sys.SMALLMONEY,
PROCEDURE = bitsmallmoneymi
);

CREATE FUNCTION sys.smallmoneybitpl(sys.SMALLMONEY, sys.BIT)
RETURNS sys.SMALLMONEY
AS $$
BEGIN
IF $2 = 0 THEN
RETURN (SELECT sys.fixeddecimalint4pl($1, 0));
ELSE
RETURN (SELECT sys.fixeddecimalint4pl($1, 1));
END IF;
END;
$$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION sys.smallmoneybitmi(sys.SMALLMONEY, sys.BIT)
RETURNS sys.SMALLMONEY
AS $$
BEGIN
IF $2 = 0 THEN
RETURN (SELECT sys.fixeddecimalint4mi($1, 0));
ELSE
RETURN (SELECT sys.fixeddecimalint4mi($1, 1));
END IF;
END;
$$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE;

CREATE OPERATOR sys.+ (
LEFTARG = sys.SMALLMONEY,
RIGHTARG = sys.BIT,
COMMUTATOR = +,
PROCEDURE = smallmoneybitpl
);

CREATE OPERATOR sys.- (
LEFTARG = sys.SMALLMONEY,
RIGHTARG = sys.BIT,
PROCEDURE = smallmoneybitmi
);

CREATE FUNCTION sys.bitpl(sys.BIT, sys.BIT)
RETURNS bool
AS 'babelfishpg_common', 'bitpl'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION sys.bitmi(sys.BIT, sys.BIT)
RETURNS bool
AS 'babelfishpg_common', 'bitmi'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE OPERATOR sys.+ (
LEFTARG = sys.BIT,
RIGHTARG = sys.BIT,
COMMUTATOR = +,
PROCEDURE = bitpl
);

CREATE OPERATOR sys.- (
LEFTARG = sys.BIT,
RIGHTARG = sys.BIT,
PROCEDURE = bitmi
);
Original file line number Diff line number Diff line change
Expand Up @@ -1641,22 +1641,22 @@ LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION sys.fixeddecimalpl(sys.SMALLMONEY, sys.SMALLMONEY)
RETURNS sys.SMALLMONEY
AS 'babelfishpg_money', 'fixeddecimalpl'
AS 'babelfishpg_money', 'smallmoneypl'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION sys.fixeddecimalmi(sys.SMALLMONEY, sys.SMALLMONEY)
RETURNS sys.SMALLMONEY
AS 'babelfishpg_money', 'fixeddecimalmi'
AS 'babelfishpg_money', 'smallmoneymi'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION sys.fixeddecimalmul(sys.SMALLMONEY, sys.SMALLMONEY)
RETURNS sys.SMALLMONEY
AS 'babelfishpg_money', 'fixeddecimalmul'
AS 'babelfishpg_money', 'smallmoneymul'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION sys.fixeddecimaldiv(sys.SMALLMONEY, sys.SMALLMONEY)
RETURNS sys.SMALLMONEY
AS 'babelfishpg_money', 'fixeddecimaldiv'
AS 'babelfishpg_money', 'smallmoneydiv'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION sys.fixeddecimalmod(sys.SMALLMONEY, sys.SMALLMONEY)
Expand Down Expand Up @@ -1703,22 +1703,22 @@ CREATE OPERATOR sys.% (

CREATE FUNCTION sys.fixeddecimalint8pl(sys.SMALLMONEY, INT8)
RETURNS sys.SMALLMONEY
AS 'babelfishpg_money', 'fixeddecimalint8pl'
AS 'babelfishpg_money', 'smallmoneyint8pl'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION sys.fixeddecimalint8mi(sys.SMALLMONEY, INT8)
RETURNS sys.SMALLMONEY
AS 'babelfishpg_money', 'fixeddecimalint8mi'
AS 'babelfishpg_money', 'smallmoneyint8mi'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION sys.fixeddecimalint8mul(sys.SMALLMONEY, INT8)
RETURNS sys.SMALLMONEY
AS 'babelfishpg_money', 'fixeddecimalint8mul'
AS 'babelfishpg_money', 'smallmoneyint8mul'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION sys.fixeddecimalint8div(sys.SMALLMONEY, INT8)
RETURNS sys.SMALLMONEY
AS 'babelfishpg_money', 'fixeddecimalint8div'
AS 'babelfishpg_money', 'smallmoneyint8div'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE OPERATOR sys.+ (
Expand Down Expand Up @@ -1749,22 +1749,22 @@ CREATE OPERATOR sys./ (

CREATE FUNCTION sys.fixeddecimalint4pl(sys.SMALLMONEY, INT4)
RETURNS sys.SMALLMONEY
AS 'babelfishpg_money', 'fixeddecimalint4pl'
AS 'babelfishpg_money', 'smallmoneyint4pl'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION sys.fixeddecimalint4mi(sys.SMALLMONEY, INT4)
RETURNS sys.SMALLMONEY
AS 'babelfishpg_money', 'fixeddecimalint4mi'
AS 'babelfishpg_money', 'smallmoneyint4mi'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION sys.fixeddecimalint4mul(sys.SMALLMONEY, INT4)
RETURNS sys.SMALLMONEY
AS 'babelfishpg_money', 'fixeddecimalint4mul'
AS 'babelfishpg_money', 'smallmoneyint4mul'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION sys.fixeddecimalint4div(sys.SMALLMONEY, INT4)
RETURNS sys.SMALLMONEY
AS 'babelfishpg_money', 'fixeddecimalint4div'
AS 'babelfishpg_money', 'smallmoneyint4div'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE OPERATOR sys.+ (
Expand Down Expand Up @@ -1795,22 +1795,22 @@ CREATE OPERATOR sys./ (

CREATE FUNCTION sys.fixeddecimalint2pl(sys.SMALLMONEY, INT2)
RETURNS sys.SMALLMONEY
AS 'babelfishpg_money', 'fixeddecimalint2pl'
AS 'babelfishpg_money', 'smallmoneyint2pl'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION sys.fixeddecimalint2mi(sys.SMALLMONEY, INT2)
RETURNS sys.SMALLMONEY
AS 'babelfishpg_money', 'fixeddecimalint2mi'
AS 'babelfishpg_money', 'smallmoneyint2mi'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION sys.fixeddecimalint2mul(sys.SMALLMONEY, INT2)
RETURNS sys.SMALLMONEY
AS 'babelfishpg_money', 'fixeddecimalint2mul'
AS 'babelfishpg_money', 'smallmoneyint2mul'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION sys.fixeddecimalint2div(sys.SMALLMONEY, INT2)
RETURNS sys.SMALLMONEY
AS 'babelfishpg_money', 'fixeddecimalint2div'
AS 'babelfishpg_money', 'smallmoneyint2div'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE OPERATOR sys.+ (
Expand Down Expand Up @@ -1839,32 +1839,30 @@ CREATE OPERATOR sys./ (
PROCEDURE = fixeddecimalint2div
);


CREATE FUNCTION sys.int8fixeddecimalpl(INT8, sys.SMALLMONEY)
RETURNS sys.SMALLMONEY
AS 'babelfishpg_money', 'int8fixeddecimalpl'
AS 'babelfishpg_money', 'int8smallmoneypl'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION sys.int8fixeddecimalmi(INT8, sys.SMALLMONEY)
RETURNS sys.SMALLMONEY
AS 'babelfishpg_money', 'int8fixeddecimalmi'
AS 'babelfishpg_money', 'int8smallmoneymi'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION sys.int8fixeddecimalmul(INT8, sys.SMALLMONEY)
RETURNS sys.SMALLMONEY
AS 'babelfishpg_money', 'int8fixeddecimalmul'
AS 'babelfishpg_money', 'int8smallmoneymul'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION sys.int8fixeddecimaldiv(INT8, sys.SMALLMONEY)
RETURNS DOUBLE PRECISION
AS 'babelfishpg_money', 'int8fixeddecimaldiv'
AS 'babelfishpg_money', 'int8smallmoneydiv'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION sys.int8fixeddecimaldiv_smallmoney(INT8, sys.SMALLMONEY)
RETURNS sys.SMALLMONEY
AS $$
SELECT sys.int8fixeddecimaldiv($1, $2)::sys.SMALLMONEY;
$$ LANGUAGE SQL IMMUTABLE STRICT PARALLEL SAFE;
AS 'babelfishpg_money', 'int8smallmoneydiv'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE OPERATOR sys.+ (
LEFTARG = INT8,
Expand Down Expand Up @@ -1894,29 +1892,28 @@ CREATE OPERATOR sys./ (

CREATE FUNCTION sys.int4fixeddecimalpl(INT4, sys.SMALLMONEY)
RETURNS sys.SMALLMONEY
AS 'babelfishpg_money', 'int4fixeddecimalpl'
AS 'babelfishpg_money', 'int4smallmoneypl'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION sys.int4fixeddecimalmi(INT4, sys.SMALLMONEY)
RETURNS sys.SMALLMONEY
AS 'babelfishpg_money', 'int4fixeddecimalmi'
AS 'babelfishpg_money', 'int4smallmoneymi'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION sys.int4fixeddecimalmul(INT4, sys.SMALLMONEY)
RETURNS sys.SMALLMONEY
AS 'babelfishpg_money', 'int4fixeddecimalmul'
AS 'babelfishpg_money', 'int4smallmoneymul'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION sys.int4fixeddecimaldiv(INT4, sys.SMALLMONEY)
RETURNS DOUBLE PRECISION
AS 'babelfishpg_money', 'int4fixeddecimaldiv'
AS 'babelfishpg_money', 'int4smallmoneydiv'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION sys.int4fixeddecimaldiv_smallmoney(INT4, sys.SMALLMONEY)
RETURNS sys.SMALLMONEY
AS $$
SELECT sys.int4fixeddecimaldiv($1, $2)::sys.SMALLMONEY;
$$ LANGUAGE SQL IMMUTABLE STRICT PARALLEL SAFE;
AS 'babelfishpg_money', 'int4smallmoneydiv'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE OPERATOR sys.+ (
LEFTARG = INT4,
Expand Down Expand Up @@ -1946,17 +1943,17 @@ CREATE OPERATOR sys./ (

CREATE FUNCTION sys.int2fixeddecimalpl(INT2, sys.SMALLMONEY)
RETURNS sys.SMALLMONEY
AS 'babelfishpg_money', 'int2fixeddecimalpl'
AS 'babelfishpg_money', 'int2smallmoneypl'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION sys.int2fixeddecimalmi(INT2, sys.SMALLMONEY)
RETURNS sys.SMALLMONEY
AS 'babelfishpg_money', 'int2fixeddecimalmi'
AS 'babelfishpg_money', 'int2smallmoneymi'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION sys.int2fixeddecimalmul(INT2, sys.SMALLMONEY)
RETURNS sys.SMALLMONEY
AS 'babelfishpg_money', 'int2fixeddecimalmul'
AS 'babelfishpg_money', 'int2smallmoneymul'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

CREATE FUNCTION sys.int2fixeddecimaldiv(INT2, sys.SMALLMONEY)
Expand Down Expand Up @@ -2014,4 +2011,4 @@ LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
CREATE FUNCTION sys.moneysmaller(sys.MONEY, sys.MONEY)
RETURNS sys.MONEY
AS 'babelfishpg_money', 'fixeddecimalsmaller'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
Loading
Loading