postgresql/lightdb的 is distinct from、is not distinct from
在 postgresql/lightdb 开发过程中有时会用到 is distinct from 和 is not distinct from 这个功能。
is distinct from
功能描述
A和B的数据类型、值不完全相同返回 true
A和B的数据类型、值完全相同返回 false
将空值视为相同。
postgres=# \x Expanded display is on. postgres=# select 1 is distinct from 1, 1 is distinct from 2, 1 is distinct from '1', '1' is distinct from '1', 1 is distinct from null, null is distinct from null ; -[ RECORD 1 ] ?column? | f ?column? | t ?column? | f ?column? | f ?column? | t ?column? | f
is not distinct from
功能描述
A和B的数据类型、值不完全相同返回 false
A和B的数据类型、值完全相同返回 true
将空值视为相同。
postgres=# \x Expanded display is on. postgres=# select 1 is not distinct from 1, 1 is not distinct from 2, 1 is not distinct from '1', '1' is not distinct from '1', 1 is not distinct from null, null is not distinct from null ; -[ RECORD 1 ] ?column? | t ?column? | f ?column? | t ?column? | t ?column? | f ?column? | t
第三条看起来有点不太符合规则
postgres=# select 1 is not distinct from '1'; -[ RECORD 1 ] ?column? | t
为 t ,这怎么理解了?
postgres=# select pg_typeof(1),pg_typeof('1'); -[ RECORD 1 ]------ pg_typeof | integer pg_typeof | unknown
有意思吧,pg_typeof(‘1’) 居然是 unknown, 而我们把它想象成字符串了。
postgres=# select 1 is not distinct from cast('1' as varchar); ERROR: operator does not exist: integer = character varying LINE 1: select 1 is not distinct from cast('1' as varchar); ^ HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. postgres=# select 1 is not distinct from cast('1' as int); ?column? ---------- t (1 row)
postgres=# select cast('1' as varchar) is not distinct from 1; ERROR: operator does not exist: character varying = integer LINE 1: select cast('1' as varchar) is not distinct from 1; ^ HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. postgres=# select cast('1' as varchar) is not distinct from cast('1' as varchar); ?column? ---------- t (1 row)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
2021-01-05 [ERROR] code: 505, UNEXPECTED_FRAME - expected content header for class 60, got non content header frame instead, recoverable: false, server: true. Error: RabbitMQ Connection Closed
2017-01-05 glibc运行时库/gcc/gdb各版本发布时间以及rhel/centos默认glibc版本、lsb对应关系
2017-01-05 mysql主从之slave-skip-errors和sql_slave_skip_counter