Expand description
Mods for a window frame — which rows around the current one a window function sees.
From https://www.sqlite.org/syntax/frame-spec.html:
{ RANGE | ROWS | GROUPS }
{ UNBOUNDED PRECEDING | expr PRECEDING | CURRENT ROW
| BETWEEN { UNBOUNDED PRECEDING | expr PRECEDING | CURRENT ROW | expr FOLLOWING }
AND { expr PRECEDING | CURRENT ROW | expr FOLLOWING | UNBOUNDED FOLLOWING } }
[ EXCLUDE { NO OTHERS | CURRENT ROW | GROUP | TIES } ]Read that inner list carefully: UNBOUNDED FOLLOWING appears only as a
frame-end and UNBOUNDED PRECEDING only as a frame-start. So there is no
from_unbounded_following and no to_unbounded_preceding here — PostgreSQL’s
grammar lists both in both positions and leaves the server to refuse them,
SQLite’s diagram does not, and a construct a dialect’s grammar lacks should not
be representable.
Two of the grammar’s defaults are relied on rather than written: the mode
defaults to RANGE, and the start bound to UNBOUNDED PRECEDING. So a to_*
mod on its own gives a complete BETWEEN UNBOUNDED PRECEDING AND …, and
BETWEEN appears exactly when there is an end bound.
use keelson_sqlite::{arg, f, frame};
// count(*) OVER (ROWS BETWEEN ?1 PRECEDING AND CURRENT ROW EXCLUDE TIES)
let e = f("count", "*").over((
frame::rows(),
frame::from_preceding(arg(3i32)),
frame::to_current_row(),
frame::exclude_ties(),
));Functions§
- exclude_
current_ row EXCLUDE CURRENT ROW.- exclude_
group EXCLUDE GROUP— the current row and all its peers.- exclude_
no_ others EXCLUDE NO OTHERS— the default, written out.- exclude_
ties EXCLUDE TIES— the current row’s peers, but not the row itself.- from_
current_ row CURRENT ROWas the start bound.- from_
following offset FOLLOWINGas the start bound. Only legal inside aBETWEEN, so pair it with ato_*mod.- from_
preceding offset PRECEDINGas the start bound.- from_
unbounded_ preceding UNBOUNDED PRECEDINGas the start bound — the default, written out.- groups
GROUPS— the offsets are counts of peer groups. Requires anORDER BYon the window.- range
RANGE— the offsets are values compared against theORDER BYkey. The grammar’s default, so this only ever documents intent.- rows
ROWS— the offsets are row counts.- to_
current_ row CURRENT ROWas the end bound. Turns the frame into aBETWEEN.- to_
following offset FOLLOWINGas the end bound. Turns the frame into aBETWEEN.- to_
preceding offset PRECEDINGas the end bound. Turns the frame into aBETWEEN.- to_
unbounded_ following UNBOUNDED FOLLOWINGas the end bound. Turns the frame into aBETWEEN.