SQL语法错误在尝试将int添加到内部的列中以进行循环
当前的
错误检查与您的MySQL Server版本相对应的手册,以便在1
上使用“ Long-Beach/112-E-Eldridge-ST-90807/HOME/7571273'”附近使用的正确语法。
new_url prints as
www.redfin上使用。 com/ca/ca/long-beach/112-e-eeldridge-st-90807/home/home/7571273
,当我在滤镜下手动搜索时,它确实显示在我的for_sale表上。
当我尝试将estimate_price添加到当前循环中的行中时,我会遇到语法错误。我已经尝试了我能想到的所有变体,但仍然没有成功。请指教。 estimate_price的当前值为null,该字段的当前设置为int。谢谢
mycursor.execute("SELECT web_url FROM for_sale WHERE estimate_price IS NULL")
for web in mycursor:
print(web)
url = str(web)
new_url = url[10:-3]
print("NEW URL",new_url)
## IN PUT IT IN THAT SAME LINE.
mycursor.execute(f"UPDATE for_sale SET estimate_price = 120000 WHERE web_url = {new_url}")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如Barmar上面提到的那样,您应该使用查询参数而不是F串。这是在Python中进行操作的方法:
MySQL的Python连接器将负责引用该价值并在必要时逃脱任何特殊字符。或者,如果您创建了光标,则为,它将使用准备和执行的适当查询参数,因此该值永远不会与SQL语法结合使用。
As Barmar mentions above, you should use a query parameter instead of an f-string. This is the way to do it in Python:
The Python connector for MySQL will take care of quoting the value and escaping any special characters if necessary. Or if you created the cursor as the MySQLPreparedCursor subclass, it'll use proper query parameters with PREPARE and EXECUTE, so the value is never combined with the SQL syntax.