【问题标题】:PostgreSQL - empty values that are not null and not empty stringsPostgreSQL - 非空值且非空字符串的空值
【发布时间】:2025-12-15 05:40:01
【问题描述】:

我在 PostgreSQL 表上运行了这个查询:

select * wkt from table  where column <>'' and  column is not null

..并且意外地收到了几行在该列中没有可见值的行。为什么是这样?对于这些行,该列中是否存在一些“隐藏”值、损坏的表或其他内容?

【问题讨论】:

  • 我相信很多值是不可见的,例如 ascii 0,1,2,3,4,5,6,7,虽然取决于客户端
  • 或者只是空格。
  • 你用 ascii 函数检查第一个字符

标签: sql postgresql notnull


【解决方案1】:
t=# select ascii(chr(9));
 ascii
-------
     9
(1 row)

因此

select ascii(column) from table  where column <>'' and  column is not null

应该给出想法

https://www.postgresql.org/docs/current/static/functions-string.html

参数第一个字符的ASCII码。对于 UTF8 返回 字符的 Unicode 代码点。对于其他多字节 编码,参数必须是 ASCII 字符。

【讨论】:

    最近更新 更多