diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2020-09-09 20:16:28 +0200 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2020-09-09 20:16:28 +0200 |
commit | 0aa8f764088ea0f36620ae2955fa6c54ec736c46 (patch) | |
tree | 875e0b1d49121b331e7471770a8e92b9ef91f37d /src/backend/utils/adt/cash.c | |
parent | a273dcc6fd34c8b6aa290fafa45e516ccd8d907d (diff) | |
download | postgresql-0aa8f764088ea0f36620ae2955fa6c54ec736c46.tar.gz postgresql-0aa8f764088ea0f36620ae2955fa6c54ec736c46.zip |
Expose internal function for converting int64 to numeric
Existing callers had to take complicated detours via
DirectFunctionCall1(). This simplifies a lot of code.
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/42b73d2d-da12-ba9f-570a-420e0cce19d9@phystech.edu
Diffstat (limited to 'src/backend/utils/adt/cash.c')
-rw-r--r-- | src/backend/utils/adt/cash.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/backend/utils/adt/cash.c b/src/backend/utils/adt/cash.c index 6515fc8ec69..d093ce80386 100644 --- a/src/backend/utils/adt/cash.c +++ b/src/backend/utils/adt/cash.c @@ -1042,7 +1042,7 @@ cash_numeric(PG_FUNCTION_ARGS) fpoint = 2; /* convert the integral money value to numeric */ - result = DirectFunctionCall1(int8_numeric, Int64GetDatum(money)); + result = NumericGetDatum(int64_to_numeric(money)); /* scale appropriately, if needed */ if (fpoint > 0) @@ -1056,8 +1056,7 @@ cash_numeric(PG_FUNCTION_ARGS) scale = 1; for (i = 0; i < fpoint; i++) scale *= 10; - numeric_scale = DirectFunctionCall1(int8_numeric, - Int64GetDatum(scale)); + numeric_scale = NumericGetDatum(int64_to_numeric(scale)); /* * Given integral inputs approaching INT64_MAX, select_div_scale() @@ -1107,7 +1106,7 @@ numeric_cash(PG_FUNCTION_ARGS) scale *= 10; /* multiply the input amount by scale factor */ - numeric_scale = DirectFunctionCall1(int8_numeric, Int64GetDatum(scale)); + numeric_scale = NumericGetDatum(int64_to_numeric(scale)); amount = DirectFunctionCall2(numeric_mul, amount, numeric_scale); /* note that numeric_int8 will round to nearest integer for us */ |