# Multiplying INT columns with DECIMALS results in INT results

**URL:** <https://community.cratedb.com/t/multiplying-int-columns-with-decimals-results-in-int-results/95>\
**Category:** SQL\
**Created:** [January 10, 2019, 7:25am UTC](https://community.cratedb.com/t/multiplying-int-columns-with-decimals-results-in-int-results/95 "2019-01-10T07:25:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dominik](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/dominik/32/57_2.png) [@Dominik](https://community.cratedb.com/u/Dominik)\
**Post date:** [January 10, 2019, 7:25am UTC](https://community.cratedb.com/t/multiplying-int-columns-with-decimals-results-in-int-results/95/1 "2019-01-10T07:25:53Z")

</div>

Observation:  
When we multiply using values - `SELECT 1 / (10*1.0 - 5*1.0)` the return value is a fraction. If however we use integer fields of a CrateDB table instead of fixed values, the return value is an `INT` but it should be a fraction.

1. Create table `testintfieldval(val1 INTEGER, val2 INTEGER);`
2. insert some sample integer values in these fields - `1440, 1268`.
3. Run `SELECT 1 / (val1 * 1.0 - val2 * 1.0) from testintfieldval` . The query returns 0 instead of the expected fraction value (0.0045…)

Is this a bug on CrateDB or expected?

---

<div class="post-metadata">

**Author:** ![yash](https://avatars.discourse-cdn.com/v4/letter/y/f17d59/32.png) [@yash](https://community.cratedb.com/u/yash)\
**Post date:** [January 10, 2019, 9:07am UTC](https://community.cratedb.com/t/multiplying-int-columns-with-decimals-results-in-int-results/95/2 "2019-01-10T09:07:34Z")

</div>

This is working as expected. In CrateDB, the columns have higher priority in our type inference logic to avoid expensive queries. For E.g. `where int_column = 8` (where 8 is a long) shouldn’t result in `int_column::long = 8` , but the other way around to utilize the lucene index efficiently.

As a workaround, we would need to add manual casts to the query with integer fields. For the above query, `SELECT 1 / (val1 * 1.0 - val2 * 1.0 :: float) from testintfieldval` after the cast ([https://crate.io/docs/crate/reference/en/latest/general/ddl/data-types.html?highlight=cast#type-conversion](https://crate.io/docs/crate/reference/en/latest/general/ddl/data-types.html?highlight=cast#type-conversion)) will return the expected output.
