【SQL】使用UPDATE修改表字段的时候,遇到1054 或者1064的问题怎么办?

我在使用python连接sql修改表格的时间字段的时候,遇到这样一个问题:

ProgrammingError: (pymysql.err.ProgrammingError) (1064 , "You have an

error in your SQL syntax; check the manual that corresponds to your

MariaDB server version for the right syntax to use near

'14:41:32.713604 WHERE table_id ='1'' at line 1")

SQL: UPDATE jd_shop_comparison1_new SET create_time =2025-07-09 14:41:32.713604 WHERE table_id ='1' \] (Background on this error at: https://sqlalche.me/e/14/f405)

原代码:

python 复制代码
UPDATE_SQL = f"UPDATE table_name SET create_time ={create_time} WHERE table_id ='{table_id}' " #修改时间
engine.execute(UPDATE_SQL)

这个错误是由于 SQL 语句中的日期时间值没有正确使用引号引起的。

在我的 UPDATE 语句中,日期时间值 create_time 没有被引号包围,导致 MariaDB 无法正确解析这个值。

解决方法:

使用字符串引号包围括号里的字符,包括日期、时间、文本等

例如:

c 复制代码
UPDATE_SQL = f"UPDATE jd_shop_comparison1_new SET create_time = '{create_time}' WHERE table_id ='{table_id}' " #修改时间
engine.execute(UPDATE_SQL)

最终问题就解决了!

详细的错误图:

相关推荐
Gracker1 小时前
Android Weekly #202520
android
TTBIGDATA2 小时前
【支持Ubuntu22】Ambari3.0.0+Bigtop3.2.0——Step7—Mariadb初始化
数据库·ambari·hdp·mariadb·bigtop·ttbigdata·hidataplus
大得3692 小时前
django的数据库原生操作sql
数据库·sql·django
tuokuac2 小时前
SQL中的HAVING用法
数据库·sql
爬山算法2 小时前
MySQL(173)MySQL中的存储过程和函数有什么区别?
数据库·mysql
jnrjian2 小时前
利用trigger对大表在线同步 UDI
数据库·sql
Ruimin05192 小时前
Mysql集群技术
数据库·mysql
lifallen2 小时前
深入解析RocksDB的MVCC和LSM Tree level
大数据·数据结构·数据库·c++·lsm-tree·lsm tree
weixin_411191842 小时前
原生安卓与flutter混编的实现
android·flutter
呼啸长风2 小时前
记一次未成功的 MMKV Pull Request
android·ios·开源