小编Cap*_*hab的帖子

PostgreSQL:插入缺失值

我在 PostgreSQL 中有一个带有时间戳和值的表。
我想在“lat”下插入缺失的值。

“lat”下的值是基准面以上的潮汐高度。为此,可以在两个已知值之间线性插入缺失值。

在 PostgreSQL 中执行此操作的最佳方法是什么?

数据库摘录

编辑20200825

我使用 QGIS 字段计算器以不同的方式解决了这个问题。这种方法的问题是:它需要很长时间,并且该进程在客户端运行,我想直接在服务器上运行它。

分步骤来说,我的工作流程是:

  1. 记录的“lat”值之间的间隔为 10 分钟。我计算了两个记录值之间每分钟的增量,并将其存储在记录的“lat”值处名为“tidal_step”的额外列中。(我将时间戳也存储为列中的“纪元”)

在QGIS中:

tidal_step =
-- the lat value @ the epoch, 10 minutes or 600000 miliseconds from the current epoch: 
(attribute(get_feature('werkset','epoch',("epoch"+'600000')),'lat') -
-- the lat value @ the current
attribute(get_feature('werkset','epoch',"epoch"),'lat'))
/10
Run Code Online (Sandbox Code Playgroud)

对于示例图像中的前两个值,结果为: (4.95 - 5.07) /10 = -0.012

  1. 我确定了要插值的“lat”值的分钟数,超过了记录“lat”值的最后记录实例并将其存储在列中:“min_past_rec”

在QGIS中:

left(
right("timestamp",8) --this takes the timestamp and goes 8 charakters from the right
,1) -- this takes the string from the previous right( and goes …
Run Code Online (Sandbox Code Playgroud)

postgresql

5
推荐指数
1
解决办法
2249
查看次数

标签 统计

postgresql ×1