I am trying to manipulate a string column by applying a REGEXP pattern to it.
All values are actually floats but converted to string. Point is to remove any trailing zeros from the numbers as shown below.
input -> output
1.000 -> 1
1.100 -> 1.1
1.001 -> 1.001
0.001 -> 0.001
0.010 -> 0.01
I can use the REGEXP ^(\d+(?:\.\d*?[1-9](?=0|\b))?)\.?0*$
to achieve the above as shown here.
Problem: How do apply the above REGEXP to all rows of a string column using SQLalchemy? The manipulation has to be done on the database side, moving data out of the DB is not an option due to the size of the data.
The Postgres equivalent is:
select TRIM(trailing '00' FROM CAST(numeric_col::decimal(32, 8) as text))
from my_table;
Any help is appreciated.