sql - 保存查询结果而不将其附加到 PostgreSQL 中的现有表中
问题描述
我有一个包含和列的表路和一个空列。使用以下脚本:gid
geom
distance
INSERT INTO road (distance)
SELECT ST_length(a.geom::geography,true)/1000
FROM road a;
我只得到附加到现有路标表的结果。我想知道是否有办法从distance
列的开头保存我的查询结果,以便它们与现有的gid
;
解决方案
you probably are looking for update?
update road set distance = ST_length(geom::geography,true)/1000;
try it within a transaction to be able to rollback:
begin;
update road set distance = ST_length(geom::geography,true)/1000;
select * from road; --to check the result
rollback; -- or commit if you like it
推荐阅读
- sorting - icetool 读取带有日期的输入文件并覆盖到另一个文件中
- mysql - sql查询正常但存储过程输出错误
- node.js - 在 nextjs HTML 中编写 nodejs 脚本
- process - nvidia-smi中的G和C类型是什么意思?
- java - 通过 javamail 应用程序读取电子邮件时出错
- java - 如何在 GraphView Android 中添加特定点?
- flutter - 如何将底栏连接到底页的顶部?
- java - Spring Data:JPA 和嵌套事务
- java - 如何将方法输出传递给数组元素?
- ruby - 如何对graphql ruby中的嵌套字段进行排序?