I am trying to remove whitespaces from a column in a Postgres table.
I am using SQLAlchemy to do it.
e.g. ' some value ' should become 'some value'.
My code is:
sqlalchemy.func.regexp_replace(
# replace whitespaces with a single space
sqlalchemy.func.regexp_replace(source_column_instance, ' {2,}', ' ', 'g'),
# also remove leading and trailing whitespaces
'^ | $', '', 'g')
The above is working fine but I want to merge the two regexes into one.