psyco2.error.syntax语法error:syntax error 输入结束时)

6l7fqoea  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(770)

我在试着运行一个 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)
                                                                       ^

我能得到一些帮助吗?

nukf8bse

nukf8bse1#

在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]))

相关问题