首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >psyco2.error.syntax错误:输入末尾出现语法错误)

psyco2.error.syntax错误:输入末尾出现语法错误)
EN

Stack Overflow用户
提问于 2020-06-08 08:18:18
回答 1查看 44关注 0票数 0

我正在尝试用python运行一个sql查询。它确实可以在pgadmin中工作,但是python报告了语法错误。

代码语言:javascript
复制
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)
                                                                       ^

我能得到一些帮助吗?

EN

回答 1

Stack Overflow用户

发布于 2020-06-08 13:54:23

在Python中,您需要使用三引号来生成多行字符串:

代码语言:javascript
复制
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]))
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62253280

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档