我有下面的postgreSql表stock
,下面的结构是列insert_time
有一个默认值now()
| column | pk | type |
+-------------+-----+-----------+
| id | yes | int |
| type | yes | enum |
| c_date | | date |
| qty | | int |
| insert_time | | timestamp |
我试图copy
以下是df
我使用psycopg
将df
上传到表stock
cur.copy_from(df, stock, null='', sep=',')
conn.commit()
正在获取此错误。在
DataError: missing data for column "insert_time"
CONTEXT: COPY stock, line 1: "001,CB04,2015-01-01,700"
我希望使用psycopg copy_from函数,我的postgresql表将在插入时自动填充行。在
| id | type | date | qty | insert_time |
+-----+------+------------+------+---------------------+
| 001 | CB04 | 2015-01-01 | 700 | 2018-07-25 12:00:00 |
| 155 | AB01 | 2015-01-01 | 500 | 2018-07-25 12:00:00 |
| 300 | AB01 | 2015-01-01 | 1500 | 2018-07-25 12:00:00 |
您可以指定如下列:
cur.copy_from(df, stock, null='', sep=',', columns=('id', 'type', 'c_date', 'qty'))
相关问题 更多 >
编程相关推荐