douglas_forsell - 8 months ago 52

SQL Question

So in this example the SQL is returning a row that has the columns "quantidade" and "quantidade_reservada", each containing the value "110", type double precision:

When I try to apply a condition to retrieve only results where "quantidade" is not equal to "quantidade_reservada", PostgreSQL does not seem to differentiate the numbers.

How is 110 different from 110?

Answer

The data types real and double precision are inexact, variable-precision numeric types.

Try

```
where round(quantidade::numeric, 2) != round(quantidade_reservada::numeric, 2)
```

Source (Stackoverflow)