FUNCTION窗口函数
lag
返回分区中在当前行之前offset行的value;如果没有这样的行,则返回default(必须与value相兼容的类型)。
Returns value evaluated at the row that is offset rows before the current row within the partition; if there is no such row, instead returns default (which must be of a type compatible with value).
窗口函数 引入 9.0(基线) 现存至 20 devel 1 条签名 2 次签名变更
- 分组
- 窗口函数
- 签名数
- 1 条
- 引入版本
- 9.0(基线)
- 状态
- 现存
- 签名变更
- 2 次
- 本版来源
- 本站译文
版本轨迹
相对 PostgreSQL 17 无变化。
签名
PostgreSQL 18 里 lag 的 1 条签名,按上游手册顺序排列。参数名用斜体,类型用弱化色, 之后是返回类型。说明取自本站手册译文:标「沿用」的借用了另一版的译文,标「EN」的本站暂无译文、按英文原文显示。
-
lag(valueanycompatible[,offsetinteger[,defaultanycompatible]] ) →anycompatible返回分区中在当前行之前offset行的value;如果没有这样的行,则返回default(必须与value相兼容的类型)。offset和default都是针对当前行求值的。 如果省略,offset默认为1,default为NULL。
演化历史
相邻两个大版本之间的差异,新的在前。版本号链到该版的签名。
-
PostgreSQL 19 ← 18 签名变更
lag ( value anycompatible [, offset integer [, default anycompatible ]] ) [ null treatment ] → anycompatiblelag ( value anycompatible [, offset integer [, default anycompatible ]] ) → anycompatible -
PostgreSQL 14 ← 13 签名变更
lag ( value anycompatible [, offset integer [, default anycompatible ]] ) → anycompatiblelag ( value anyelement [, offset integer [, default anyelement ]] ) → anyelement说明更新 -
PostgreSQL 13 ← 12 手册重排
这一跳手册重排了函数表的写法,签名文本整体改写,只记函数的增删,不逐条比较签名。
签名矩阵
每条签名在给出了签名的 18 个版本里的存在情况;方格指向该版的签名。只在正文里提到此函数、没有给出签名的版本不列进来,上面的版本轨迹里仍然有它们。签名文本在 PostgreSQL 13 前后写法不同,跨越那一跳的同一条签名会显示成两行。
存在 不存在
| 签名 | 9.0 | 9.1 | 9.2 | 9.3 | 9.4 | 9.5 | 9.6 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
lag ( value anyelement [, offset integer [, default anyelement ]] ) → same type as value |
存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 |
lag ( value anyelement [, offset integer [, default anyelement ]] ) → anyelement |
不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 |
lag ( value anycompatible [, offset integer [, default anycompatible ]] ) → anycompatible |
不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 存在 | 存在 | 存在 | 存在 | 存在 | 不存在 | 不存在 |
lag ( value anycompatible [, offset integer [, default anycompatible ]] ) [ null treatment ] → anycompatible |
不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 不存在 | 存在 | 存在 |
同组函数
| 函数 | 签名 | 主签名 | 版本变动 | 最近变更 |
|---|---|---|---|---|
first_value基线 |
1 | first_value ( value anyelement ) [ null treatment ] → anyelement |
191 次 | |
| 返回在窗口帧的第一行求得的value。 | 现存 | |||
lag基线 |
1 | lag ( value anycompatible [, offset integer [, default anycompatible ]] ) [ null treatment ] → anycompatible |
192 次 | |
| 返回分区中在当前行之前offset行的value;如果没有这样的行,则返回default(必须与value相兼容的类型)。 | 现存 | |||
last_value基线 |
1 | last_value ( value anyelement ) [ null treatment ] → anyelement |
191 次 | |
| 返回在窗口帧的最后一行求得的value。 | 现存 | |||
lead基线 |
1 | lead ( value anycompatible [, offset integer [, default anycompatible ]] ) [ null treatment ] → anycompatible |
192 次 | |
| 返回分区中在当前行之后offset行的value; 如果没有这样的行,则返回default(必须与value兼容的类型)。 | 现存 | |||
nth_value基线 |
1 | nth_value ( value anyelement, n integer ) [ null treatment ] → anyelement |
191 次 | |
| 返回在窗口帧的第n行求得的value(从1开始计数);如果没有这样的行,则返回NULL。 | 现存 | |||
ntile基线 |
1 | ntile ( num_buckets integer ) → integer |
— | |
| 返回一个从1到参数值的整数,并将分区划分为尽可能相等的值。 | 现存 | |||
row_number基线 |
1 | row_number () → bigint |
— | |
| 返回其分区内的当前行数,从1开始计数。 | 现存 | |||