【发布时间】:2020-04-04 23:27:16
【问题描述】:
我正在为 python 插入一些数据,这些数据来自像 JSON 这样的 API FLASK 中的 GET,由于某种原因,当 python 将插入这些数据或者可能是 postgres 本身时,它正在删除 000000
数据 json:
{
"datecollect": 1585983000000
}
插入 py:
conn.execute('''INSERT INTO "TBLNAME"
(value1,value2,value3,value4,value5)
VALUES ('{0}','{1}','{2}',to_timestamp({3}) AT TIME ZONE 'UTC',current_timestamp)'''.
format(server,forecastmemory,levelerror,datecollect))
原定日期:
select to_timestamp(1585983000000) AT TIME ZONE 'UTC' --> 52227-10-20 17:20:00
python 插入 pgsql 的日期:
select to_timestamp(1585983) AT TIME ZONE 'UTC' --> 1970-01-19 08:33:03
转换正确:
即使使用网站的时区,它也会返回一个问题select to_timestamp(1585983000000) AT TIME ZONE 'GMT-03:00' --> 52227-10-20 20:20:00
【问题讨论】:
标签: python sql postgresql psycopg2