【问题标题】:How to insert null decimals / datetime into MYSQL from python?如何从python将空小数/日期时间插入MYSQL?
【发布时间】:2012-04-09 03:16:34
【问题描述】:

我有数据文件:

'Laura', 'Laura Ellenburg', '5342 Picklied Trout Lane', 'Nashville', 'TN',
'38010','2000-02-22', ' ', '454-56-768'

注意结尾附近的“”。

我正在使用python代码:

  data = []
  infile = open ("./BIGPVFC-ASC10e/Employee.asc", "r")
  for line in infile:
    line = line.rstrip("\n")
    line = line.strip()
    seq = line.split(", ")
    for i in range(0,9):
      seq[i] = seq[i].strip("'")
    seq = tuple (seq)
    data.append(seq)
  infile.close()

  cursor.executemany ("""insert into PV_employee
  (employeeid, employeename, employeeaddress, employeecity, employeestate,
   employeezip, employeedatehired, employeebirthdate, employeesupervisor)
   values (%s, %s, %s, %s, %s, %s, %s, %s, %s)""", data)

我的桌子是:

create table PV_employee
 (employeeid         varchar(10)    not null
 ,employeename       varchar(25)    null
 ,employeeaddress    varchar(30)    null
 ,employeecity       varchar(20)    null
 ,employeestate      char(2)        null
 ,employeezip        varchar(10)         null  
 ,employeedatehired  datetime       null
 ,employeebirthdate  datetime      null
 ,employeesupervisor varchar(10)    null
 ,primary key (employeeid)
);

我在哪里得到错误“警告:列.....的值超出范围”

在小数点为空的情况下,我得到“警告:不正确的十进制值:' ' for column ...”

我尝试将' ' 更改为'''NULL'NULL。这些似乎都不起作用。有什么建议吗?

【问题讨论】:

    标签: python mysql mysql-python


    【解决方案1】:

    SQL NULL 的 Python 等效项是 None

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-25
      • 2013-04-27
      • 2013-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-23
      相关资源
      最近更新 更多