Python Can';在Postgresql psycopg2中插入时间戳
我试图在Postresql查询的列中将时间戳作为值插入,但我尝试过以各种不同的方式获取所有类型的格式化错误 我有3个是时间戳:时间戳,开始日期,结束日期Python Can';在Postgresql psycopg2中插入时间戳,python,postgresql,Python,Postgresql,我试图在Postresql查询的列中将时间戳作为值插入,但我尝试过以各种不同的方式获取所有类型的格式化错误 我有3个是时间戳:时间戳,开始日期,结束日期 start_date = datetime.strptime('2020-03-17 16:00:00', "%Y-%m-%d %H:%M:%S").timestamp() end_date = datetime.strptime('2020-03-17 16:00:00', "%Y-%m-%d %H:%M:%S").timestamp()
start_date = datetime.strptime('2020-03-17 16:00:00', "%Y-%m-%d %H:%M:%S").timestamp()
end_date = datetime.strptime('2020-03-17 16:00:00', "%Y-%m-%d %H:%M:%S").timestamp()
sql_insert_query = 'INSERT INTO public.table(time_stamp, name, name_short, geo, link, img_url, source, type, category, start_date, end_date, quantity, remaining)' \
' VALUES ( current_timestamp, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,%s, %s);'
insert_tuple = (item['name'],'name_short',item['language'],item['_url'],item['image_url'],'_API',item['coupon_type'],item['category'],start_date ,end_date,coupon_limits,item['unused'])
cur = conn.cursor()
cur.execute(sql_insert_query, insert_tuple)
错误为(与翻译的不完全相同):
在SQL表中,我将列声明为
不带时区的时间戳时间戳现在不为空默认值(),
无时区的开始日期时间戳,
结束日期时间戳不带时区不为空,
>>类型(datetime.now().timestamp())
返回由错误消息明确指示的
。尝试删除.timestamp()
谢谢,这解决了问题
psycopg2.ProgrammingError: the column «start_date» is of type timestamp without time zone but the expression is type numeric