SQL语法错误在尝试将int添加到内部的列中以进行循环

发布于 2025-01-24 08:01:02 字数 774 浏览 2 评论 0 原文

当前的

错误检查与您的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}")

CURRENT

ERROR check the manual that corresponds to your MySQL server version for the right syntax to use near 'Long-Beach/112-E-Eldridge-St-90807/home/7571273' at line 1

new_url prints as www.redfin.com/CA/Long-Beach/112-E-Eldridge-St-90807/home/7571273 which does show up on my for_sale Table when i search it manually under the filter.

i keep getting a syntax error when i'm trying to add an estimate_price to the row in the current for loop. I've tried every variation i can think of but still no success. Please advise. The current value of estimate_price is NULL, the current setting for that field is INT. Thank You

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

远昼 2025-01-31 08:01:02

正如Barmar上面提到的那样,您应该使用查询参数而不是F串。这是在Python中进行操作的方法:

mycursor.execute("UPDATE for_sale SET estimate_price = 120000 WHERE web_url = %s", [new_url])

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:

mycursor.execute("UPDATE for_sale SET estimate_price = 120000 WHERE web_url = %s", [new_url])

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文