Reputation: 3058
I'm looking for a way to get rid of surplus spaces at the end of perfectly fine cell values. That would be all two spaces or more at the end of a cell value. Some cell values contain spaces between words. The sed command for such value would have been sed -re 's/\s{2,}*$//'
. As far as I know REPLACE()
doesn't support patterns at all nor backward replacement groups (\0 \1 and so on) and REGEXP()
(from the externally-loaded library) doesn't do replacements.
Upvotes: 0
Views: 148
Reputation: 222432
In SQLite, you can use string function rtrim()
to remove spaces at the end of a string.
select rtrim(mycol) from mytable
If you want to remove trim only values that have at least two spaces and leave values that end with a single space untouched, you can wrap this in a condition:
select case when mycol like '% ' then rtirm(mycol) else mycol end from mytable
Or if you are looking for an update
statement:
update mytable set mycol = rtrim(mycol) where mycol like '% '
Upvotes: 1