python - 无法将时间戳插入 Postgresql psycopg2
问题描述
我正在尝试将时间戳作为我的 Postresql 查询的列中的值,但我很想以各种不同的方式得到各种格式错误,我已经尝试过了。
我有 3 个作为时间戳的列:time_stamp、start_date、end_date
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)
错误是(不准确的翻译):
psycopg2.ProgrammingError: the column «start_date» is of type timestamp without time zone but the expression is type numeric
在 SQL 表上,我已将列声明为 time_stamp timestamp without time zone NOT NULL DEFAULT now(), start_date timestamp without time zone, end_date timestamp without time zone NOT NULL,
解决方案
推荐阅读
- c# - 如何通过单击按钮使表单标题动态更改?
- google-analytics - 谷歌分析活动/来源/媒体未显示
- python - 为什么对 zip() 调用的列表理解会返回一个包含 zip 对象的列表,而不是 zip() 的返回值列表?
- c - 如何将 STDIN 传递给程序并将其输出存储到变量中?C
- jenkins - Jenkins 中的自动部署构建失败
- python - Python - 拖放到终端作为输入?macOS -zsh
- html - 执行两个 url 之一的 webview
- node.js - 显示肥皂响应角
- wpf - 非常规网格状结构,具有灵活的项目大小
- java - 使用 xpath 从肥皂服务获取响应(错误:前缀必须解析为命名空间:soap)