PostgreSQL - empty values that are not null and not empty strings

JasonBK picture JasonBK · Jan 25, 2018 · Viewed 9.4k times · Source

I ran this query on a PostgreSQL table:

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

..and unexpectedly received several rows with no visible value in that column. Why is this? Is there some 'hidden' value in that column for those rows, or a corrupted table, or something else?

Answer

Vao Tsun picture Vao Tsun · Jan 25, 2018
t=# select ascii(chr(9));
 ascii
-------
     9
(1 row)

thus

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

should give the idea

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

ASCII code of the first character of the argument. For UTF8 returns the Unicode code point of the character. For other multibyte encodings, the argument must be an ASCII character.