How to find all rows whose column value has either a leading or trailing space (either single or multiple or just empty. I would like to filter all rows which has the above condition.
This is what I tried
select '"' || url || '"' from urls;
How to find all rows whose column value has either a leading or trailing space (either single or multiple or just empty. I would like to filter all rows which has the above condition.
This is what I tried
select '"' || url || '"' from urls;
2
Answers
SELECT * FROM table WHERE column_name <> REGEXP_REPLACE(column_name, '^s+|s+$', '');
The above seems to work
Postgres provides a full set on String Functions. Here use
length()
andtrim()
.Trim()
and companion functionsltrim()
, andrtrim(), removes any leading and/or trailing spaces. The
length()` function returns the number of characters/bytes in the string. So here select those rows where the length of the string is not the same as the length of the string with leading and trailing spaced removed.