I am working on a Flask application which maps an existing datamodel built in Postgresql. I have mapped the tables using automap and can query the objects properly:
Base = automap_base()
Base.prepare(db.engine, reflect=False)
Object1 = Base.classes.table1
I am now querying table1 and I need to retrieve a timeseries-like list. The object has a numeric value and a datetime in TIMESTAMP postgresql format.
When I run the query and try to export result as a json with jsonify
query = session.query(Object1.value, Object1.createtime).order_by(Object1.createtime.desc())
return jsonify(str(query.all()))
I get this result back:
"[(5543157, datetime.datetime(2021, 4, 3, 7, 29, 53)), (5543156, datetime.datetime(2021, 4, 3, 7, 29, 37))]"
how can I get back a unix timestamp instead of the datetime.datetime format? I would like to avoid to go through a loop to convert every element as the query might retrieve more than 1M elements.