0

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

2 Answers 2

1

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'))
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.