Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Can';在Postgresql psycopg2中插入时间戳_Python_Postgresql - Fatal编程技术网

Python Can';在Postgresql psycopg2中插入时间戳

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()

我试图在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()

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