Reputation: 18790
I have a column type text which looks like empty string but the length of it is 1.
the following sql
select
teilnetz_name,
length(teilnetz_name),
trim(teilnetz_name),
length(trim(teilnetz_name))
from test_table
results in
teilnetz_name| length| btrim| length
| 1 | | 1
and
select case when trim(teilnetz_name) is distinct from '' then true else false end
from test_table
--return true
select case when teilnetz_name is distinct from null then true else false end
from test_table
--return true
select case when teilnetz_name is distinct from '' then true else false end
from test_table
--return true
select case when teilnetz_name is distinct from ' ' then true else false end
from test_table
--return true
How can I explain this phenomenon ?
I have on postgreql version 12.3
Upvotes: 0
Views: 381
Reputation: 13049
There may be a non-printable unicode character in field teilnetz_name
.
Try
select encode(teilnetz_name, 'hex') from test_table;
in order to see what teilnetz_name
actually contains.
Upvotes: 0
Reputation:
The column probably contains some other whitespace, e.g. a tab character. trim()
will only remove real spaces.
Try
length(regexp_replace(teilnetz_name, '\s+', '', 'g'))
Upvotes: 1