douglas_forsell douglas_forsell - 26 days ago 12
SQL Question

PostgreSQL treating the same values as different

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

Floating-Point Types:

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

Try

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

Arbitrary Precision Numbers

Comments