【问题标题】:Python MySQL Parameterized Queries with date带有日期的 Python MySQL 参数化查询
【发布时间】:2017-09-14 15:42:11
【问题描述】:

我在 django 中使用了一个 sql 查询,其中参数是日期:

query="select DT_ORA_INSERIMENTO from richieste where DT_ORA_INSERIMENTO=%s", datestart

但是以这种方式我收到错误:

not enough arguments for format string

似乎 django 不会用他的值替换变量的值 (2017-09-02 00:00:00).. 怎么了?

【问题讨论】:

  • query="select DT_ORA_INSERIMENTO from richieste where DT_ORA_INSERIMENTO='%s'", datestart 无论如何替换 绑定

标签: python mysql sql django


【解决方案1】:
query="select DT_ORA_INSERIMENTO from richieste where DT_ORA_INSERIMENTO=%s"%datestart

【讨论】:

  • 按照建议,我在 /getdata/ 处收到错误 DatabaseError(1064,“您的 SQL 语法有错误;请查看与您的 MySQL 服务器版本相对应的手册,以了解在 ' 附近使用的正确语法00:00:00' 在第 1 行")。
  • 听起来 datestart 格式错误。运行“SELECT CURRENT_TIMESTAMP FROM richieste”以了解如何格式化日期
猜你喜欢
  • 2014-06-21
  • 1970-01-01
  • 1970-01-01
  • 2010-10-13
  • 2018-01-22
  • 2018-04-10
  • 2014-07-11
  • 2020-10-02
  • 2016-07-23
相关资源
最近更新 更多