How to bind a double precision using psycopg2

Posted by user337636 on Stack Overflow See other posts from Stack Overflow or by user337636
Published on 2010-05-10T21:16:43Z Indexed on 2010/05/10 21:54 UTC
Read the original article Hit count: 244

Filed under:
|

I'm trying to bind a float to a postgresql double precision using psycopg2.

ele = 1.0/3.0
dic = {'name': 'test', 'ele': ele}
sql = '''insert into waypoints (name, elevation) values (%(name)s, %(ele)s)'''

cur = db.cursor()
cur.execute(sql, dic)
db.commit()

sql = """select elevation from waypoints where name = 'test'"""
cur.execute(sql_out)
ele_out = cur.fetchone()[0]

ele_out
0.33333333333300003
ele
0.33333333333333331

Obviously I don't need the precision, but I would like to be able to simply compare the values. I could use the struct module and save it as a string, but thought there should be a better way. Thanks

© Stack Overflow or respective owner

Related posts about python

Related posts about psycopg2