从 SQLite 上的 WITH 子句更新数据
Update data from a WITH clause on SQLite
我有一个 table **属性 **,其中记录了 postgis 坐标列 geoarea(点)和布尔列 within_area(Bool) 确定它是否在另一个 postgis 的内部 st_union(Polygon) from table 市区
select properties.id, ST_Within(properties.geoarea,st_transform("urbanArea"."st_union",2393)) from properties,"urbanArea"
which returns 我通过 id 和 bool 值(如果它在区域内)的属性中的所有记录。执行查询大约需要 10 秒
我现在想从 select 语句中获取值并将其插入 within_area 专栏,我想出了这个 SQL 查询,但它永远挂起并且没有完成,知道为什么吗?
UPDATE properties p
SET within_area = (
with newarea as (select properties.id, ST_Within(properties.geoarea,st_transform("urbanArea"."st_union",2393)) as "isInside" from properties,"urbanArea")
select u."isInside" from newarea u where u.id = p.id
)
我也试过用 CTE 做,但它仍然永远挂起。
with newarea as (select properties.id, ST_Within(properties.geoarea,st_transform("urbanArea"."st_union",2393)) from properties, "urbanArea")
UPDATE properties
SET
withinurban=newa.st_within
FROM properties prop
INNER JOIN
newarea newa
ON prop.id = newa.id
在您的第二个查询中移除 properties
的额外连接:
WITH newarea AS (
SELECT p.id,
ST_Within(p.geoarea, ST_Transform(u."st_union", 2393)) st_within
FROM properties p, "urbanArea" u
)
UPDATE properties p
SET withinurban = n.st_within
FROM newarea n
WHERE p.id = n.id;
但是,您的代码似乎只相当于:
UPDATE properties p
SET withinurban = ST_Within(p.geoarea, ST_Transform(u."st_union", 2393))
FROM "urbanArea" u;
或:
UPDATE properties p
SET withinurban = ST_Within(p.geoarea, ST_Transform((SELECT "st_union" FROM "urbanArea"), 2393));
我有一个 table **属性 **,其中记录了 postgis 坐标列 geoarea(点)和布尔列 within_area(Bool) 确定它是否在另一个 postgis 的内部 st_union(Polygon) from table 市区
select properties.id, ST_Within(properties.geoarea,st_transform("urbanArea"."st_union",2393)) from properties,"urbanArea"
which returns 我通过 id 和 bool 值(如果它在区域内)的属性中的所有记录。执行查询大约需要 10 秒
我现在想从 select 语句中获取值并将其插入 within_area 专栏,我想出了这个 SQL 查询,但它永远挂起并且没有完成,知道为什么吗?
UPDATE properties p
SET within_area = (
with newarea as (select properties.id, ST_Within(properties.geoarea,st_transform("urbanArea"."st_union",2393)) as "isInside" from properties,"urbanArea")
select u."isInside" from newarea u where u.id = p.id
)
我也试过用 CTE 做,但它仍然永远挂起。
with newarea as (select properties.id, ST_Within(properties.geoarea,st_transform("urbanArea"."st_union",2393)) from properties, "urbanArea")
UPDATE properties
SET
withinurban=newa.st_within
FROM properties prop
INNER JOIN
newarea newa
ON prop.id = newa.id
在您的第二个查询中移除 properties
的额外连接:
WITH newarea AS (
SELECT p.id,
ST_Within(p.geoarea, ST_Transform(u."st_union", 2393)) st_within
FROM properties p, "urbanArea" u
)
UPDATE properties p
SET withinurban = n.st_within
FROM newarea n
WHERE p.id = n.id;
但是,您的代码似乎只相当于:
UPDATE properties p
SET withinurban = ST_Within(p.geoarea, ST_Transform(u."st_union", 2393))
FROM "urbanArea" u;
或:
UPDATE properties p
SET withinurban = ST_Within(p.geoarea, ST_Transform((SELECT "st_union" FROM "urbanArea"), 2393));