Skip to content

Commit f01d2e9

Browse files
tanyagupta17yashneet vinayak
authored and
yashneet vinayak
committed
Handling CASE expression when one branch is of decimal/numeric and other branch is of smallmoney/money. (babelfish-for-postgresql#3719)
Currently, we treat typmod for smallmoney/money datatype as default which leads to output differences in many cases. Following are the fixes introduced in this PR : Introduce typmod handling for smallmoney/money datatype for objects like table/procedure/views/functions/casts and handling their upgrade scenarios. We are also handling p&s for declared variables, nested case expressions and unions having smallmoney/money as one of it's node. It also takes case of round vs truncation behaviour around edge cases for fixeddecimal multiplication Money/smallmoney and Numeric Arithmetic operations - precision and sclae correction and fixing TDS protocol Errors. T_Param node handling for fixeddecimal dataypes (money and smallmoney) when numeric is another operand. T_Aggref handling for Sum/Avg for fixeddecimal and other fixed length datatypes when numeric is another operand. Handing typmod for smallmoney/money in pg catalogs for views metadata and during dump-restore. Handling money/smallmoney typmod and fixeddecimal typmodin during dump-restore and by-passing typmod while deparsing for ISC check constraint. Avoiding crashes and wrong results by updating sanity checks and setting intermittent result size appropirately for bigint and fixeddecimal multiplication. Signed-off-by: Tanya Gupta [email protected] Engine PR : babelfish-for-postgresql/postgresql_modified_for_babelfish#575
1 parent 181d813 commit f01d2e9

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

contrib/babelfishpg_tsql/src/pltsql_coerce.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,7 @@ resolve_numeric_typmod_from_exp(Plan *plan, Node *expr, bool *found)
12281228
case T_Param:
12291229
{
12301230
Param *param = (Param *) expr;
1231+
12311232
if (param->paramtypmod == -1)
12321233
{
12331234
/* UDT handling in T_Param */
@@ -1247,11 +1248,11 @@ resolve_numeric_typmod_from_exp(Plan *plan, Node *expr, bool *found)
12471248
return ((BIGINT_PRECISION_RADIX << 16) | 0) + VARHDRSZ;
12481249
else if (param->paramtype == INT2OID)
12491250
return ((SMALLINT_PRECISION_RADIX << 16) | 0) + VARHDRSZ;
1250-
else if (plan && (*common_utility_plugin_ptr->is_tsql_tinyint_datatype) (param->paramtype))
1251-
return ((TINYINT_PRECISION_RADIX << 16) | 0) + VARHDRSZ;
12521251
}
12531252

1254-
if (!is_numeric_datatype(param->paramtype))
1253+
if (!is_numeric_datatype(param->paramtype) &&
1254+
!(*common_utility_plugin_ptr->is_tsql_money_datatype)(param->paramtype) &&
1255+
!(*common_utility_plugin_ptr->is_tsql_smallmoney_datatype)(param->paramtype))
12551256
{
12561257
/* typmod is undefined */
12571258
if (found != NULL) *found = false;
@@ -1831,7 +1832,8 @@ resolve_numeric_typmod_from_exp(Plan *plan, Node *expr, bool *found)
18311832
* tinyint, smallint, int will have aggtype type as int
18321833
* bigint will have aggtype type as bigint.
18331834
*/
1834-
if ((*common_utility_plugin_ptr->is_tsql_money_datatype)(aggref->aggtype))
1835+
if ((*common_utility_plugin_ptr->is_tsql_money_datatype)(aggref->aggtype) ||
1836+
(*common_utility_plugin_ptr->is_tsql_smallmoney_datatype)(aggref->aggtype))
18351837
{
18361838
return TSQL_MONEY_TYPMOD;
18371839
}

0 commit comments

Comments
 (0)