【SQL查询】发现查询结果与预期结果不同,使用了not与@>进行搭配

首先我有两套环境。一个是opengauss数据库((openGauss 6.0.1 build db72a150),一个是postgresql数据库(15.4)

同样的sql在两套环境中得到的结果不同。

我的表名为tp,其中有个列叫做tpAttrs是一个jsonb对象。其中值类似

{“uni”: false}

该值也可能不存在,所以之前的逻辑是,查为true的取反,下面结果可以看到postgresql是可以正常取得结果的,但是openguass却得到了空。

需要详细数据的话,我在评论里再贴把。

opengauss中进行查询

select * from tp where not (tpAttrs@>‘{“uni”:true}’);

image

select * from tp where (tpAttrs@>‘{“uni”:false}’);

postgresql中进行查询则都有结果

uap_nem=>
uap_nem=> select * from tp where (tpAttrs@>‘{“uni”:false}’);

uap_nem=> select * from tp where not (tpAttrs@>‘{“uni”:true}’);