我正在编写一个python脚本,以便在PostgreSQL 11.0表中插入值。该列的日期信息格式为MonthYear(如2016年5月)
我在代码中使用以下行插入值
q2 = """insert into %s.test_trial2enrollment_1 (trial_id, enrollment, enrollment_type, primary_completion_date, primary_completion_type, study_completion_date, study_completion_type, study_start, last_version_checked)
values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');""" % (staging_schema, id_ ,enr_val, enr_type, to_date(prm_val, 'MonYYYY'), prm_type, to_date(end_val, 'MonYYYY'), end_type, sta, str(clinical_trial_version - 1))
cur.execute(q2)
我得到以下错误
NameError: name 'to_date' is not defined
如何使用以下格式插入日期值
May2016
Nov2018
Mar2020
非常感谢您的帮助
为此:
此处的每个文档:
向SQL查询传递参数 https://www.psycopg.org/docs/usage.html#passing-parameters-to-sql-queries
相关问题 更多 >
编程相关推荐