-
Notifications
You must be signed in to change notification settings - Fork 94
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
Implement modulo operator for MONEY/SMALLMONEY types #3401
base: BABEL_5_X_DEV
Are you sure you want to change the base?
Implement modulo operator for MONEY/SMALLMONEY types #3401
Conversation
386761a
to
1797ac5
Compare
Pull Request Test Coverage Report for Build 12757649408Details
💛 - Coveralls |
5c824a3
to
a428399
Compare
Description ----------- Due to the missing modulo operator for MONEY/SMALLMONEY types, it will choose the other Postgres internal alternatives like int4mod and numeric_mod, which will involve additional implicit CASTing between MONEY/SMALLMONEY types and other types. These CASTings could cause loss of precision and wrong results. What's more, the result of calculation won't be MONEY/SMALLMONEY types any more. Fix --- Implement the modulo function and operator for MONEY/SMALLMONEY types. The reason why we don't need to implement the functions between MONEY/SMALLMONEY types and interger types is that it will choose the MONEY-MONEY/SMALLMONEY-SMALLMONEY functions to calculate. And the result type is expected. Task: BABEL-5480 Signed-off-by: Bo Li <[email protected]>
a428399
to
4c83ac0
Compare
AS 'babelfishpg_money', 'fixeddecimalmod' | ||
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE; | ||
|
||
DROP OPERATOR IF EXISTS sys.% (sys.MONEY, sys.MONEY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there could be user defined objects depend on this. so lets create try..catch.. block where we only create operator if it does not exist.
DO $$
BEGIN
IF NOT EXISTS(SELECT 1 FROM pg_catalog.pg_operator WHERE oprleft = 'numeric'::pg_catalog.regtype and oprright = 'int4'::pg_catalog.regtype and oprnamespace = 'sys'::regnamespace and oprname = '<' and oprresult != 0) THEN
CREATE OPERATOR sys.< (
LEFTARG = numeric,
RIGHTARG = int4,
FUNCTION = sys.numeric_int4_lt,
COMMUTATOR = >,
NEGATOR = >=,
RESTRICT = scalarltsel,
JOIN = scalarltjoinsel
);
END IF;
END $$;
@@ -542,3 +542,292 @@ smallmoney | |||
1.8000 | |||
~~END~~ | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should have upgrade test cases, prepare/verify/cleanup format
Description
Due to the missing modulo operator for MONEY/SMALLMONEY types, it will choose the other Postgres internal alternatives like int4mod and numeric_mod, which will involve additional implicit CASTing between MONEY/SMALLMONEY types and other types. These CASTings could cause loss of precision and wrong results. What's more, the result of calculation won't be MONEY/SMALLMONEY types any more.
Fix
Implement the modulo function and operator for MONEY/SMALLMONEY types. The reason why we don't need to implement the functions between MONEY/SMALLMONEY types and interger types is that it will choose the MONEY-MONEY/SMALLMONEY-SMALLMONEY functions to calculate. And the result type is expected.
Task: BABEL-5480
Check List
By submitting this pull request, I confirm that my contribution is under the terms of the Apache 2.0 and PostgreSQL licenses, and grant any person obtaining a copy of the contribution permission to relicense all or a portion of my contribution to the PostgreSQL License solely to contribute all or a portion of my contribution to the PostgreSQL open source project.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.