I am facing problem in retrieving long value from PostgreSQL
I use the following SQL command :
SELECT *, (extract(epoch FROM start_timestamp) * 1000) FROM lot
WHERE EXTRACT(EPOCH FROM lot.start_timestamp) * 1000 >=1265299200000 AND
EXTRACT(EPOCH FROM lot.start_timestamp) * 1000 <=1265990399999
ORDER BY start_timestamp DESC limit 9 offset 0
I am interested in the unix timestamp in ms
I run this command manually through pgAdmin.
From pgAdmin, I saw 1265860762817 for column (extract(epoch FROM start_timestamp) * 1000)
However, when I retrieve through psycopg2, here is what I use :
cur = conn.cursor()
cur.execute(sql)
rows = cur.fetchall()
for row in rows :
print row[3]
And here is what I get :
1.26586076282e+12
I pass this value, from python cgi to JavaScript in JSON
If I do manual conversion in JavaScript
1.26586076282e+12
// summary.date is 1.26586076282e+12
var timestamp = summary.date * 1;
// Get 1265860762820
alert(timestamp);
There are 3ms error difference
1265860762817
1265860762820-
==============
3
==============
How can I avoid such error? I can I make sure psycopg2 is returning me 1265860762817, not 1.26586076282e+12