dhis2-core icon indicating copy to clipboard operation
dhis2-core copied to clipboard

fix: cast numeric type in SqlLiteral [DHIS2-13925]

Open vietnguyen opened this issue 1 year ago • 2 comments

https://dhis2.atlassian.net/browse/DHIS2-13925

Issue

  • User create programIndicator with expression "22/10"
  • Expected result returned by api/analytic is "2.2". However "2" is returned.

Fix

  • The Expression parser doesn't have ::numeric cast in the sql query. Therefore, a select statement select 22/10" in postgresql will always return "2". We need to cast either "22" or "10" to numeric` so postgreSQL will not ignore the decimal.
  • The expected sql query generated should be select 22::numeric/10::numeric
  • I have add a new NumericLiteral which do numeric cast if the expression contains a math equation which matches regex pattern "^[0-9+\\-*/]+$"

vietnguyen avatar Jul 02 '24 03:07 vietnguyen

Closing this PR can't be merged because it contains unsigned commit. Create a new one here https://github.com/dhis2/dhis2-core/pull/20162

vietnguyen avatar Mar 06 '25 15:03 vietnguyen