python - psyco2.error.syntax 错误:输入末尾的语法错误)
问题描述
我正在尝试sql
在 python 中运行查询。它确实在 中工作pgadmin
,但 python 报告了语法错误。
cur_str.execute("select b2.linestring,b2.id,ST_Length(ST_Intersection(ST_Transform(ST_MakeValid(b2.linestring),28992),ST_Transform(ST
_MakeValid(b1.geom), 28992))) from public.ways b2, public.pc4_2017 b1 where ST_Intersects(ST_Transform(ST_MakeValid(b2.linestring),28992)
,ST_Transform(ST_MakeValid(b1.geom),28992)",([pc4]))
psycopg2.errors.SyntaxError: syntax error at end of input
LINE 1: ...linestring),28992),ST_Transform(ST_MakeValid(b1.geom),28992)
^
我能得到一些帮助吗?
解决方案
您需要使用三引号在 Python 中创建多行字符串:
cur_str.execute("""
select
b2.linestring,
b2.id,
ST_Length(ST_Intersection(ST_Transform(ST_MakeValid(b2.linestring),28992), ST_Transform(ST_MakeValid(b1.geom), 28992)))
from
public.ways b2,
public.pc4_2017 b1
where
ST_Intersects(ST_Transform(ST_MakeValid(b2.linestring),28992),ST_Transform(ST_MakeValid(b1.geom),28992))
""", ([pc4]))
推荐阅读
- python - 随机 numpy 数组,其值介于 -1 和 1 之间,总和为 1
- json - 空手道框架:打印 JSON 时缺少双引号
- r - 在 R 中使用 projectRaster 后,栅格范围不再正确
- plsql - 通过动态操作对页面项目进行验证
- javascript - 闪亮和数字格式中的条件文本样式
- javascript - 使用无效数据调用 Firestore 函数 DocumentReference.update()。不支持的字段值:自定义对象
- microsoft-graph-api - Microsoft Graph 邮件查询 - 获取“ErrorAccessDenied”
- swift - 我应该使用什么方法来代替已弃用的“resumeAnimation(forKey:)”?
- python - 锁定鼠标后,有什么方法可以让程序打开视频吗?
- reactjs - Netlify 网站发布但黑屏