{"Entry":{"collection":"func","key":"lag","name":"lag","aliases":[],"metadata":{"changed_in":["9.0","14","19"],"changes":[{"descriptions_changed":false,"doc_overhaul":false,"from":"8.3","group_changed":null,"signatures":{"added":[],"removed":[]},"status":"added","to":"8.4"},{"descriptions_changed":true,"doc_overhaul":false,"from":"8.4","group_changed":null,"signatures":{"added":["lag ( value anyelement [, offset integer [, default anyelement ]] ) → same type as value"],"removed":["lag ( value any [, offset integer [, default any ]] ) → same type as value"]},"status":"changed","to":"9.0"},{"descriptions_changed":false,"doc_overhaul":true,"from":"12","group_changed":null,"signatures":{"added":[],"removed":[]},"status":"changed","to":"13"},{"descriptions_changed":true,"doc_overhaul":false,"from":"13","group_changed":null,"signatures":{"added":["lag ( value anycompatible [, offset integer [, default anycompatible ]] ) → anycompatible"],"removed":["lag ( value anyelement [, offset integer [, default anyelement ]] ) → anyelement"]},"status":"changed","to":"14"},{"descriptions_changed":false,"doc_overhaul":false,"from":"18","group_changed":null,"signatures":{"added":["lag ( value anycompatible [, offset integer [, default anycompatible ]] ) [ null treatment ] → anycompatible"],"removed":["lag ( value anycompatible [, offset integer [, default anycompatible ]] ) → anycompatible"]},"status":"changed","to":"19"}],"content_hash":"70bc3d74a0e8ea4bc30075f169d4113c1090588d3ee70a5dd53b891ca5e2b263","derived_content_hash":"72b4714fa88705a1f00645ab22031c8dbab2739e4be4f1e541422dcb8ebab631","first_version":"8.4","group":"window","group_label":"Window Functions","groups":["window"],"imported_at":"2026-09-27T17:57:28.991894+08:00","last_version":"20","name":"lag","name_key":"lag","position":22001,"present_in":["8.4","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"],"repair_provenance":{"original_source_revision":"b7bd9cda","receipt_sha256":"da6063ff0253e03a76b28578fd0fd71400c8259073813f41705bae9e5f714bb5","repair":"wiki-repair-20261023"},"signature":"lag ( value anycompatible [, offset integer [, default anycompatible ]] ) [ null treatment ] → anycompatible","signature_count":1,"slug":"lag","source_rev":"wiki-repair-20261023:3a624abf9d79693182d04de9fcd562246e1b356baed798c441c9a2eb7d81dd0a","summary":"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).","summary_zh":""}},"Definition":{"Collection":"func","Key":"lag","SourceDatabase":"center","Version":"18","SourceTable":"func","SourceKey":"lag","SourceRevision":"wiki-repair-20261023:3a624abf9d79693182d04de9fcd562246e1b356baed798c441c9a2eb7d81dd0a","Facts":{"description":"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). Both offset and default are evaluated with respect to the current row. If omitted, offset defaults to 1 and default to NULL.","description_html":"Returns \u003cem class=\"parameter\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e evaluated at the row that is \u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e rows before the current row within the partition; if there is no such row, instead returns \u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e (which must be of a type compatible with \u003cem class=\"parameter\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e). Both \u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e and \u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e are evaluated with respect to the current row. If omitted, \u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e defaults to 1 and \u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e to \u003ccode class=\"literal\"\u003eNULL\u003c/code\u003e.","description_zh":"返回在分区内当前行之前 offset 行处计算的 value；如果没有这样的行，则返回 default（其类型必须与 value 兼容）。offset 和 default 都针对当前行求值。如果省略，offset 默认为 1，default 默认为 NULL。","description_zh_html":"返回在分区内当前行之前 \u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e 行处计算的 \u003cem class=\"parameter\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e；如果没有这样的行，则返回 \u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e（其类型必须与 \u003cem class=\"parameter\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e 兼容）。\u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e 和 \u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e 都针对当前行求值。如果省略，\u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e 默认为 1，\u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e 默认为 \u003ccode class=\"literal\"\u003eNULL\u003c/code\u003e。","doc":{"anchor":"FUNCTIONS-WINDOW-TABLE","file":"functions-window.html","slug":"18"},"group":"window","group_label":"Window Functions","lang":"en","layout":"table-new","pages":["functions-window.html"],"prose_only":false,"signatures":[{"description":"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). Both offset and default are evaluated with respect to the current row. If omitted, offset defaults to 1 and default to NULL.","description_html":"Returns \u003cem class=\"parameter\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e evaluated at the row that is \u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e rows before the current row within the partition; if there is no such row, instead returns \u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e (which must be of a type compatible with \u003cem class=\"parameter\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e). Both \u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e and \u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e are evaluated with respect to the current row. If omitted, \u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e defaults to 1 and \u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e to \u003ccode class=\"literal\"\u003eNULL\u003c/code\u003e.","description_zh":"返回在分区内当前行之前 offset 行处计算的 value；如果没有这样的行，则返回 default（其类型必须与 value 兼容）。offset 和 default 都针对当前行求值。如果省略，offset 默认为 1，default 默认为 NULL。","description_zh_html":"返回在分区内当前行之前 \u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e 行处计算的 \u003cem class=\"parameter\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e；如果没有这样的行，则返回 \u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e（其类型必须与 \u003cem class=\"parameter\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e 兼容）。\u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e 和 \u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e 都针对当前行求值。如果省略，\u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e 默认为 1，\u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e 默认为 \u003ccode class=\"literal\"\u003eNULL\u003c/code\u003e。","examples":[],"html":"\u003ccode class=\"function\"\u003elag\u003c/code\u003e ( \u003cem class=\"parameter\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e \u003ccode class=\"type\"\u003eanycompatible\u003c/code\u003e [\u003cspan class=\"optional\"\u003e, \u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e \u003ccode class=\"type\"\u003einteger\u003c/code\u003e [\u003cspan class=\"optional\"\u003e, \u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e \u003ccode class=\"type\"\u003eanycompatible\u003c/code\u003e\u003c/span\u003e ]\u003c/span\u003e] ) → \u003ccode class=\"returnvalue\"\u003eanycompatible\u003c/code\u003e","returns":"anycompatible","text":"lag ( value anycompatible [, offset integer [, default anycompatible ]] ) → anycompatible","zh_from":"same-version-pgdoc"}],"translation_provenance":{"inputs":[{"kind":"current-pgdoc-translation","path":"/Users/vonng/pgsty/pgdoc/zh/18/html/functions-window.html","sha256":"859f0e20306eeaf9a15406f95e01cb81a166cfbe2fd21534fc44df3f903b4e6d"}],"kind":"same-version-pgdoc","locale":"zh-Hans","source_revision":"b1b500221dbe5437cfca004d6b04d3f6e422765d","version":"18"},"zh_from":"same-version-pgdoc"},"ManualEvidence":{"doc":{"anchor":"FUNCTIONS-WINDOW-TABLE","file":"functions-window.html","slug":"18"}},"MeasuredEvidence":{}},"Text":{"Collection":"func","Key":"lag","SourceDatabase":"center","Version":"18","Locale":"en","Title":"lag","Summary":"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). Both offset and default are evaluated with respect to the current row. If omitted, offset defaults to 1 and default to NULL.","BodyHTML":"Returns \u003cem\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e evaluated at the row that is \u003cem\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e rows before the current row within the partition; if there is no such row, instead returns \u003cem\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e (which must be of a type compatible with \u003cem\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e). Both \u003cem\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e and \u003cem\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e are evaluated with respect to the current row. If omitted, \u003cem\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e defaults to 1 and \u003cem\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e to \u003ccode\u003eNULL\u003c/code\u003e.","SourceRevision":"wiki-repair-20261023:3a624abf9d79693182d04de9fcd562246e1b356baed798c441c9a2eb7d81dd0a","ContentHash":"fb94f6d48538e1861a6c930c7d006a5f212370471cf8b048b0a7f31615784232","Payload":{"description":"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). Both offset and default are evaluated with respect to the current row. If omitted, offset defaults to 1 and default to NULL.","description_html":"Returns \u003cem class=\"parameter\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e evaluated at the row that is \u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e rows before the current row within the partition; if there is no such row, instead returns \u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e (which must be of a type compatible with \u003cem class=\"parameter\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e). Both \u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e and \u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e are evaluated with respect to the current row. If omitted, \u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e defaults to 1 and \u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e to \u003ccode class=\"literal\"\u003eNULL\u003c/code\u003e.","signatures":[{"description":"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). Both offset and default are evaluated with respect to the current row. If omitted, offset defaults to 1 and default to NULL.","description_html":"Returns \u003cem class=\"parameter\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e evaluated at the row that is \u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e rows before the current row within the partition; if there is no such row, instead returns \u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e (which must be of a type compatible with \u003cem class=\"parameter\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e). Both \u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e and \u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e are evaluated with respect to the current row. If omitted, \u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e defaults to 1 and \u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e to \u003ccode class=\"literal\"\u003eNULL\u003c/code\u003e.","description_zh":"返回在分区内当前行之前 offset 行处计算的 value；如果没有这样的行，则返回 default（其类型必须与 value 兼容）。offset 和 default 都针对当前行求值。如果省略，offset 默认为 1，default 默认为 NULL。","description_zh_html":"返回在分区内当前行之前 \u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e 行处计算的 \u003cem class=\"parameter\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e；如果没有这样的行，则返回 \u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e（其类型必须与 \u003cem class=\"parameter\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e 兼容）。\u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e 和 \u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e 都针对当前行求值。如果省略，\u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e 默认为 1，\u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e 默认为 \u003ccode class=\"literal\"\u003eNULL\u003c/code\u003e。","examples":[],"html":"\u003ccode class=\"function\"\u003elag\u003c/code\u003e ( \u003cem class=\"parameter\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e \u003ccode class=\"type\"\u003eanycompatible\u003c/code\u003e [\u003cspan class=\"optional\"\u003e, \u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e \u003ccode class=\"type\"\u003einteger\u003c/code\u003e [\u003cspan class=\"optional\"\u003e, \u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e \u003ccode class=\"type\"\u003eanycompatible\u003c/code\u003e\u003c/span\u003e ]\u003c/span\u003e] ) → \u003ccode class=\"returnvalue\"\u003eanycompatible\u003c/code\u003e","returns":"anycompatible","text":"lag ( value anycompatible [, offset integer [, default anycompatible ]] ) → anycompatible","zh_from":"same-version-pgdoc"}]}},"RequestedLocale":"en","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20","8.4","9.0","9.1","9.2","9.3","9.4","9.5","9.6"],"Locales":["en","zh-Hans"],"Signatures":[{"Version":"18","Ordinal":0,"Hash":"df66cb7ed402ae5ddd0dfcf9f694d4ba487e5c0f30aab17b2a0a3834de5c0a62","Text":"lag ( value anycompatible [, offset integer [, default anycompatible ]] ) → anycompatible","Returns":"anycompatible","Payload":{"description":"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). Both offset and default are evaluated with respect to the current row. If omitted, offset defaults to 1 and default to NULL.","description_html":"Returns \u003cem class=\"parameter\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e evaluated at the row that is \u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e rows before the current row within the partition; if there is no such row, instead returns \u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e (which must be of a type compatible with \u003cem class=\"parameter\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e). Both \u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e and \u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e are evaluated with respect to the current row. If omitted, \u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e defaults to 1 and \u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e to \u003ccode class=\"literal\"\u003eNULL\u003c/code\u003e.","description_zh":"返回在分区内当前行之前 offset 行处计算的 value；如果没有这样的行，则返回 default（其类型必须与 value 兼容）。offset 和 default 都针对当前行求值。如果省略，offset 默认为 1，default 默认为 NULL。","description_zh_html":"返回在分区内当前行之前 \u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e 行处计算的 \u003cem class=\"parameter\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e；如果没有这样的行，则返回 \u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e（其类型必须与 \u003cem class=\"parameter\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e 兼容）。\u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e 和 \u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e 都针对当前行求值。如果省略，\u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e 默认为 1，\u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e 默认为 \u003ccode class=\"literal\"\u003eNULL\u003c/code\u003e。","examples":[],"html":"\u003ccode class=\"function\"\u003elag\u003c/code\u003e ( \u003cem class=\"parameter\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e \u003ccode class=\"type\"\u003eanycompatible\u003c/code\u003e [\u003cspan class=\"optional\"\u003e, \u003cem class=\"parameter\"\u003e\u003ccode\u003eoffset\u003c/code\u003e\u003c/em\u003e \u003ccode class=\"type\"\u003einteger\u003c/code\u003e [\u003cspan class=\"optional\"\u003e, \u003cem class=\"parameter\"\u003e\u003ccode\u003edefault\u003c/code\u003e\u003c/em\u003e \u003ccode class=\"type\"\u003eanycompatible\u003c/code\u003e\u003c/span\u003e ]\u003c/span\u003e] ) → \u003ccode class=\"returnvalue\"\u003eanycompatible\u003c/code\u003e","returns":"anycompatible","text":"lag ( value anycompatible [, offset integer [, default anycompatible ]] ) → anycompatible","zh_from":"same-version-pgdoc"}}],"Spellings":null,"SQLState":null,"Evidence":null}
