我试图在python脚本中放置一个查询,但得到错误:
psycopg2.ProgrammingError:输入结束时的语法错误LINE 1:... LOAT *(db_lo + db_hi)))END)AS Lx_pop FROM R2
我的查询如下:
sql= "DROP MATERIALIZED VIEW IF EXISTS "+schema1+"."+vue_out+";\
CREATE MATERIALIZED VIEW "+schema1+"."+vue_out+" AS\
WITH\
-- Select Population Table and transform MultiPolygons into Polygons (ST_Dump)\
P0 AS (\
SELECT\
gid\
,(ST_Dump(the_geom)).geom AS geom\
--,(ST_Dump(the_geom)).geom::geometry(Polygon,31370) AS geom\
,ST_NumGeometries(the_geom) AS Ngeom\
,pop_2014 AS tot_pop\
,ST_area(the_geom) AS tot_Area\
FROM\
"+schema2+"."+table_in_2+"\
ORDER BY ST_NumGeometries(the_geom) DESC\
),\
-- Compute Area and distribution population over Split multipolygons:\
P AS (\
SELECT\
P0.*\
,ST_area(geom) AS area\
,tot_pop*ST_area(geom)/tot_area AS pop\
FROM P0\
),\
-- Select and filter out (2016) Power Profile and transform MultiPolygons into Polygons (ST_Dump)\
N AS (\
SELECT\
gid\
,(ST_Dump(the_geom)).geom AS geom\
--,(ST_Dump(the_geom)).geom::geometry(Polygon,31370) AS geom\
,year\
,db_lo\
,db_hi\
,ST_area(the_geom) AS Area\
FROM\
"+schema1+"."+table_in_1+"\
WHERE\
year = 2016\
),\
-- Compute Intersection after joining only overlapping polygons\
R0 AS (\
SELECT\
P.gid AS pgid\
,P.pop AS tot_pop\
,P.area AS tot_area\
,N.gid AS ngid\
,N.year\
,N.db_lo\
,N.db_hi\
,(ST_Dump(ST_intersection(P.geom, N.geom))).geom AS geom\
FROM\
P JOIN N ON ST_intersects(N.geom, P.geom)\
),\
-- Compute area of intersections:\
R1 AS (\
SELECT\
row_number()over() AS gid\
,pgid\
,ngid\
,year\
,tot_pop\
,tot_area\
,db_lo\
,db_hi\
,geom::geometry(Polygon, 31370) AS geom\
,ST_area(geom) AS area\
FROM\
R0\
),\
-- Distribution population over polygons: \
R2 AS (\
SELECT\
R1.*\
,area/tot_area*tot_pop AS Pop \
FROM R1\
)\
-- Final Aggregates:\
SELECT\
R2.* \
,(CASE WHEN Pop = 0 THEN '-infinity'::FLOAT ELSE 10::FLOAT*log( pop*10::FLOAT^( 0.05::FLOAT*(db_lo+db_hi) ) ) END) AS Lx_pop\
FROM R2"
为什么我收到此错误?
我有一个类似的问题。就我而言,它是通过删除注释掉的行来解决的。 (其中有--
的那些。)