Changeset: 27d95b99462d for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/27d95b99462d Modified Files: sql/ChangeLog.Aug2024 sql/server/rel_select.c Branch: Aug2024 Log Message:
Fix rel_cast taking into account new precision and scale assumptions. Also, add ChangeLog entry. diffs (80 lines): diff --git a/sql/ChangeLog.Aug2024 b/sql/ChangeLog.Aug2024 --- a/sql/ChangeLog.Aug2024 +++ b/sql/ChangeLog.Aug2024 @@ -1,6 +1,10 @@ # ChangeLog file for sql # This file is updated with Maddlog +* Mon Oct 21 2024 Lucas Pereira <lucas.pere...@monetdbsolutions.com> +- Improve casting to generic decimal type by choosing a better fit for + precision and scale instead of defaulting to 18 and 3, respectively. + * Thu Oct 17 2024 Sjoerd Mullender <sjo...@acm.org> - When for whatever reason the upgrade code produces an error, we now exit the server. Before the server would limp on with what is basically diff --git a/sql/server/rel_select.c b/sql/server/rel_select.c --- a/sql/server/rel_select.c +++ b/sql/server/rel_select.c @@ -4069,36 +4069,35 @@ rel_cast(sql_query *query, sql_rel **rel } } - if (e->type == e_atom && tpe->type->eclass == EC_DEC) { + if (tpe->type->eclass == EC_DEC) { sql_subtype *et = exp_subtype(e); - if (et->type->eclass == EC_NUM) { - unsigned int min_precision = atom_num_digits(e->l); - if (!tpe->digits && !tpe->scale) - tpe->digits = min_precision; - if (min_precision > tpe->digits) - return sql_error(sql, 02, SQLSTATE(42000) "Precision (%d) should be at least (%d)", tpe->digits, min_precision); - tpe = sql_bind_subtype(sql->sa, "decimal", tpe->digits, et->scale); - } else if (EC_VARCHAR(et->type->eclass) && !tpe->digits && !tpe->scale) { - char *s = E_ATOM_STRING(e); - unsigned int min_precision = 0, min_scale = 0; - bool dot_seen = false; - for (size_t i = 0; i < strlen(s); i++) { - if (isdigit(s[i])) { - min_precision++; - if (dot_seen) - min_scale++; - } else if (s[i] == '.') { - dot_seen = true; + if (e->type == e_atom && !tpe->digits) { + if (et->type->eclass == EC_NUM || et->type->eclass == EC_DEC) { + tpe->digits = atom_num_digits(e->l); + tpe = sql_bind_subtype(sql->sa, "decimal", tpe->digits, et->scale); + } else if (EC_VARCHAR(et->type->eclass)) { + char *s = E_ATOM_STRING(e); + unsigned int min_precision = 0, min_scale = 0; + bool dot_seen = false; + for (size_t i = 0; i < strlen(s); i++) { + if (isdigit(s[i])) { + min_precision++; + if (dot_seen) + min_scale++; + } else if (s[i] == '.') { + dot_seen = true; + } } + tpe = sql_bind_subtype(sql->sa, "decimal", min_precision, min_scale); + } else { /* fallback */ + tpe = sql_bind_subtype(sql->sa, "decimal", 18, 3); } - tpe = sql_bind_subtype(sql->sa, "decimal", min_precision, min_scale); - } - } else if (tpe->type->eclass == EC_DEC && !tpe->digits && !tpe->scale) { - sql_subtype *et = exp_subtype(e); - if (et->type->eclass == EC_NUM) - tpe = sql_bind_subtype(sql->sa, "decimal", et->digits, 0); - else /* fallback */ - tpe = sql_bind_subtype(sql->sa, "decimal", 18, 3); + } else if (!tpe->digits && !tpe->scale) { + if (et->type->eclass == EC_NUM) + tpe = sql_bind_subtype(sql->sa, "decimal", et->digits, 0); + else /* fallback */ + tpe = sql_bind_subtype(sql->sa, "decimal", 18, 3); + } } if (e) _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org