PostgreSQL 将相同的值视为不同的

PostgreSQL treating the same values as different

因此在此示例中,SQL 返回包含列 "quantidade" 和 "quantidade_reservada" 的行,每个列都包含值“110”,类型为双精度:

当我尝试应用条件仅检索 "quantidade" 不等于 "quantidade_reservada" 的结果时,PostgreSQL 似乎无法区分数字。

110 和 110 有什么不同?

Floating-Point Types:

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

尝试

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

Arbitrary Precision Numbers

数字的值与其在 pgAdmin 中的表示不同。
您在 pgAdmin 中看到的是 2 位数比例的圆形显示值。

with t (x,y) as (select 102/300::numeric(23,20),101/300::numeric(23,20)) 

select  x
       ,y
       ,case when x=y then 'Y' else 'N' end     as is_equale
       ,x-y                                     as "x-y"
       ,(x-y)*1000                              as "(x-y)*100"

from    t
;

pgAdmin 结果:

x       y       is_equale   x-y     (x-y)*100
----    ----    ---------   ----    ---------
0.34    0.34    N           0.00    3.33

DbVisulizer 结果:

x                       y                       is_equale   x-y                     (x-y)*100
----------------------  ----------------------  ---------   ----------------------  ----------------------
0.34000000000000000000  0.33666666666666666667  N           0.00333333333333333333  3.33333333333333333000