1"use strict";(globalThis.webpackChunkstackql_io||=[]).push([[18561],{1170(e,n,t){t.r(n),t.d(n,{assets:()=>l,contentTitle:()=>o,default:()=>u,frontMatter:()=>a,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"language-spec/functions/window/lead","title":"LEAD","description":"LEAD window function in StackQL: evaluate an expression against a following row in the partition, with an optional offset and default.","source":"@site/docs/language-spec/functions/window/lead.md","sourceDirName":"language-spec/functions/window","slug":"/language-spec/functions/window/lead","permalink":"/language-spec/functions/window/lead","draft":false,"unlisted":false,"editUrl":"https://github.com/stackql/stackql.io/edit/main/docs/language-spec/functions/window/lead.md","tags":[],"version":"current","lastUpdatedAt":1791162383000,"frontMatter":{"title":"LEAD","hide_title":false,"hide_table_of_contents":false,"keywords":["stackql","infrastructure-as-code","configuration-as-data","cloud inventory"],"description":"LEAD window function in StackQL: evaluate an expression against a following row in the partition, with an optional offset and default.","image":"/img/stackql-featured-image.png"},"sidebar":"docsSidebar","previous":{"title":"LAST_VALUE","permalink":"/language-spec/functions/window/last_value"},"next":{"title":"NTH_VALUE","permalink":"/language-spec/functions/window/nth_value"}}');var i=t(74848),r=t(28453);const a={title:"LEAD",hide_title:!1,hide_table_of_contents:!1,keywords:["stackql","infrastructure-as-code","configuration-as-data","cloud inventory"],description:"LEAD window function in StackQL: evaluate an expression against a following row in the partition, with an optional offset and default.",image:"/img/stackql-featured-image.png"},o=void 0,l={},d=[{value:"Syntax",id:"syntax",level:2},{value:"Arguments",id:"arguments",level:2},{value:"Return Value(s)",id:"return-values",level:2},{value:"Examples",id:"examples",level:2},{value:"Look ahead to the next release",id:"look-ahead-to-the-next-release",level:3}];function c(e){const n={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",hr:"hr",p:"p",pre:"pre",strong:"strong",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.p,{children:"Returns the result of evaluating an expression against a subsequent row in the partition."}),"\n",(0,i.jsxs)(n.p,{children:["The first form of ",(0,i.jsx)(n.code,{children:"LEAD()"})," returns the result of evaluating the expression against the next row in the partition. Or, if there is no next row (because the current row is the last), ",(0,i.jsx)(n.code,{children:"NULL"})," is returned."]}),"\n",(0,i.jsxs)(n.p,{children:["If the offset argument is provided, it must be a non-negative integer. The value returned is the result of evaluating the expression against the row ",(0,i.jsx)(n.em,{children:"offset"})," rows after the current row within the partition. If offset is 0, the expression is evaluated against the current row. If there is no row ",(0,i.jsx)(n.em,{children:"offset"})," rows after the current row, ",(0,i.jsx)(n.code,{children:"NULL"})," is returned."]}),"\n",(0,i.jsxs)(n.p,{children:["If a default value is also provided, it is returned instead of ",(0,i.jsx)(n.code,{children:"NULL"})," if the row identified by offset does not exist."]}),"\n",(0,i.jsxs)(n.p,{children:["See also:\r\n",(0,i.jsxs)(n.a,{href:"/language-spec/select",children:["[",(0,i.jsx)(n.code,{children:"SELECT"}),"]"]})," ",(0,i.jsxs)(n.a,{href:"/language-spec/functions/window/lag",children:["[",(0,i.jsx)(n.code,{children:"LAG"}),"]"]})]}),"\n",(0,i.jsx)(n.hr,{}),"\n",(0,i.jsx)(n.h2,{id:"syntax",children:"Syntax"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sql",children:"SELECT LEAD(expr) OVER ([PARTITION BY column] ORDER BY column) FROM <multipartIdentifier>;\r\n\r\nSELECT LEAD(expr, offset) OVER ([PARTITION BY column] ORDER BY column) FROM <multipartIdentifier>;\r\n\r\nSELECT LEAD(expr, offset, default) OVER ([PARTITION BY column] ORDER BY column) FROM <multipartIdentifier>;\n"})}),"\n",(0,i.jsx)(n.h2,{id:"arguments",children:"Arguments"}),"\n",(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.em,{children:"expr"})}),"\r\nThe expression to evaluate against the subsequent row."]}),"\n",(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.em,{children:"offset"})}),"\r\nOptional. A non-negative integer specifying how many rows forward to look. Defaults to 1."]}),"\n",(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.em,{children:"default"})}),"\r\nOptional. The value to return if the offset row does not exist. Defaults to ",(0,i.jsx)(n.code,{children:"NULL"}),"."]}),"\n",(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.em,{children:"PARTITION BY column"})}),"\r\nOptional. Divides the result set into partitions. The ",(0,i.jsx)(n.code,{children:"LEAD"})," function is applied within each partition separately."]}),"\n",(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.strong,{children:(0,i.jsx)(n.em,{children:"ORDER BY column"})}),"\r\nSpecifies the order in which rows are processed."]}),"\n",(0,i.jsx)(n.h2,{id:"return-values",children:"Return Value(s)"}),"\n",(0,i.jsxs)(n.p,{children:["Returns the value of the expression evaluated against the specified subsequent row, or ",(0,i.jsx)(n.code,{children:"NULL"})," (or the default value) if no such row exists."]}),"\n",(0,i.jsx)(n.hr,{}),"\n",(0,i.jsx)(n.h2,{id:"examples",children:"Examples"}),"\n",(0,i.jsx)(n.h3,{id:"look-ahead-to-the-next-release",children:"Look ahead to the next release"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-sql",children:"-- Compare each release to previous and next release dates\r\nSELECT\r\n tag_name,\r\n name,\r\n published_at,\r\n LAG(tag_name, 1) OVER (ORDER BY published_at) as previous_release,\r\n LEAD(tag_name, 1) OVER (ORDER BY published_at) as next_release\r\nFROM github.repos.releases\r\nWHERE owner = 'stackql'\r\n AND repo = 'stackql'\r\nORDER BY published_at;\n"})}),"\n",(0,i.jsxs)(n.p,{children:["For more information, see ",(0,i.jsx)(n.a,{href:"https://sqlite.org/windowfunctions.html#built-in_window_functions",children:"https://sqlite.org/windowfunctions.html#built-in_window_functions"}),"."]})]})}function u(e={}){const{wrapper:n}={...(0,r.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(c,{...e})}):c(e)}},28453(e,n,t){t.d(n,{R:()=>a,x:()=>o});var s=t(96540);const i={},r=s.createContext(i);function a(e){const n=s.useContext(r);return s.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function o(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:a(e.components),s.createElement(r.Provider,{value:n},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.