gpt4 book ai didi

linux - 如何解决 SyntaxError : unexpected character after line continuation character in prestodb on linux?

转载 作者:太空宇宙 更新时间:2023-11-04 10:00:19 27 4
gpt4 key购买 nike

我需要从 id_1 以 E 开头的数据库中获取数据。在我为上述约束添加 Where 子句之前,代码运行良好

sql = "select inserted_at, id1, id2, id3 from data where inserted_at<=" + str(start_date_time) + " and " \
"inserted_at>=" + str(end_date_time) + " " \
"and" "where id1 like %E%"

我收到这个错误。

"inserted_at>=" + str(end_date_time) + " " \ 
^
SyntaxError: unexpected character after line continuation character

最佳答案

实际问题是由在查询中放置转义日期/日期时间文字引起的。您可以通过在 start_date_time 周围放置单引号来解决这个直接问题,但更好的长期解决方法是使用准备好的语句:

sql = "select inserted_at, id1, id2, id3 from data where inserted_at between ? and ? and id1 like '%E%'"
cur = conn.cursor()
cur.execute(sql, (start_date_time, end_date_time,))

关于linux - 如何解决 SyntaxError : unexpected character after line continuation character in prestodb on linux?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56830590/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com