we have a column in the PostgreSQL table, the column type is float(8) and in 1 record we have a value of 21.291400909423828 under that column. When we are reading from python using psycopg2 with a simple SQL query, we are getting the record but the column value is coming as 21.2914009094238 i.e., truncated by the last 2 decimal values/positions.
I have tried the below approach to customize the psycopg2 reading:
psycopg2.extras.register_uuid()
DEC2FLOAT = psycopg2.extensions.new_type(
psycopg2.extensions.FLOAT.values,
"DEC2FLOAT",
lambda value, curs: Decimal(value) if value is not None else None)
psycopg2.extensions.register_type(DEC2FLOAT)
But didn't get succeded.
The code that I'm using :
connection_pool = pool.SimpleConnectionPool(1, 10,
database=connection_string['db_name'],
user=connection_string['db_user'],
password=connection_string['db_password'],
host=connection_string['db_endpoint'], port=5432,
**keepalive_kwargs)
cursor = connection_object.cursor()
cursor.execute(query, params)
print(query, params)
records = cursor.fetchall()
It would be helpful if anyone shares their experience and thoughts on this.