AI Infrastructure
A SQL Window's Current Row Can Include Tied AI Observations
In PostgreSQL 18, ROWS BETWEEN CURRENT ROW AND CURRENT ROW includes only the current observation. With the same timestamp-only ordering, RANGE BETWEEN CURRENT ROW AND CURRENT ROW includes all its ordering peers. For the fictional values 10, 30 and 100 below, the sums are 10/30/100 versus 40/40/100. Both window projections retain three output rows. A feature delivered on each observation can therefore contain contributions from other observations.
01
Separate the partition, the frame and the output row
The partition identifies rows that can take part together in a window calculation. Within that partition, the frame identifies contributors for the current row's aggregate. The output row retains its identity even when its feature uses several contributors.
The window ordering supplies the peer relationship: rows equal on all its ordering expressions are peers. If timestamp is the only ordering expression, observations with different IDs can still be peers.
For the two explicit frames here, the ROWS bounds select the current observation alone. The RANGE bounds reach from its first ordering peer to its last. Without exclusions, that includes the whole peer group. An ordinary aggregate used as a window function computes over those frame members. These distinctions determine what a per-observation sum or mean actually represents.
02
PEER3: the same inputs and three output observations
PEER3 is a fictional arithmetic example, with no SQL query executed. Fix three observations for one asset: I1 has value 10 at 10:00, I2 has value 30 at 10:00, and I3 has value 100 at 10:01. The values are unitless, non-null feature inputs. The timestamps are exact ordering values on one stipulated same-day UTC basis, rather than rounded display labels.
All three rows belong to one asset partition. Both alternatives order by timestamp alone, ascending. There are no joins, aggregate filters or frame exclusions, and the selected input stays fixed. The window projection retains each observation ID and input value while adding its aggregate.
Compare ROWS BETWEEN CURRENT ROW AND CURRENT ROW with RANGE BETWEEN CURRENT ROW AND CURRENT ROW. Only the frame mode changes. The table lists every contributor for every output observation.
| Output observation | Exact timestamp (UTC) | Input value | ROWS members; sum | RANGE members; sum | RANGE mean | Source |
|---|---|---|---|---|---|---|
| I1 | 10:00 | 10 | I1; 10 | I1, I2; 40 | 20 | Planning analysis |
| I2 | 10:00 | 30 | I2; 30 | I1, I2; 40 | 20 | Planning analysis |
| I3 | 10:01 | 100 | I3; 100 | I3; 100 | 100 | Planning analysis |
Both alternatives retain three output observations. Member IDs identify contributors; listing them in this order does not specify a SQL output sort.
03
I2 keeps its identity while its feature changes
For I2, the ROWS frame contains only I2, so its sum and mean are both 30. Its RANGE frame contains I1 and I2: the sum is 10 + 30 = 40, and the mean is 40 divided by 2 = 20. I1 receives the same RANGE sum and mean because its peer frame contains the same two observations. I3 has a singleton frame in either comparison and receives 100.
No arbitrary ordering of I1 and I2 is needed to derive the ROWS result. With both bounds restricted to the current row, each observation contributes only to its own frame, whichever position it occupies among the timestamp ties. The three ROWS means are therefore 10/30/100.
Now suppose a later illustrative selection rule retains observations whose feature mean is at least 25. Using the singleton means, I2 and I3 qualify. Using the peer means, only I3 qualifies. This follows from the defined feature values and rule; it establishes no trained-model outcome. The unchanged observation count would miss the difference that matters to this selection.
04
Adding the ID to the window ordering changes the meaning
Keeping I1 and I2 as distinct IDs in the output identifies two observations. It does not alter their timestamp-only peer relationship.
If the window ordering instead includes timestamp followed by the unique observation ID, the ordered pairs differ. Every peer group in PEER3 then becomes a singleton. Under those changed ordering expressions, the explicit RANGE current-to-current frame would give sums and means of 10/30/100. That is a change to the feature's contributor definition.
Sorting the final display by ID is a separate choice from putting ID into the window's ordering. The latter determines peers; the former arranges presentation.
Choose the contributor definition from the intended feature meaning: each observation's own input or a shared aggregate of its timestamp peers. Equal stored timestamps alone establish neither physical simultaneity nor the scientific suitability of that grouping.
05
Evaluate contributor membership alongside row retention
A useful explanation of an offered feature identifies the database version, partition keys, window ordering, frame bounds, aggregate and any filters or exclusions. It also explains what the timestamp records. For one nonconfidential tied example, connect each output ID to its contributing IDs and the resulting value.
In PEER3, a requirement for I2's own-value mean calls for 30. A requirement for the timestamp-peer mean calls for 20. Three retained IDs cannot establish which requirement has been met.
Repeated annotations also affect later totals. Adding PEER3's RANGE sum column gives 40 + 40 + 100 = 180, while the original inputs total 140. The peer total of 40 appears on both I1 and I2; each of their inputs contributes twice to that later addition. No extra input observation was introduced in the example. Before using such a total, establish whether each input should contribute once or once per containing frame.
The related PostgreSQL snapshot guide addresses which committed state supplies the selected inputs. The historical-feature guide addresses eligible versions, and the streaming guide addresses late arrivals and finalization. Here, the selected relation is already fixed; the decision concerns contributors within it.
References: [PT18]
06
Scope any separate equipment-cabling requirement
If the wider platform project also needs physical equipment connections, Leviathan's Structured Cabling & Fiber Installation service and the related project inquiry provide a route to discuss agreed fiber and copper installation, labels and connection records.
Share a nonconfidential equipment and site outline, approved endpoints and routes, material-supply responsibilities and required physical handoff to discuss scope and availability. That inquiry concerns physical cabling; SQL feature definitions and data-processing work remain with the appointed software and database providers.
References: [L1]
07Sources
Primary sources
- [PX18]PostgreSQL 18: 4.2.8. Window Function CallsChecked 2026-10-21. Defines partitioning, the ROWS and RANGE meanings of CURRENT ROW, and frame exclusions. Applies here to explicitly bounded frames without exclusions.
- [PW18]PostgreSQL 18: 9.22. Window FunctionsChecked 2026-10-21. Defines ordering peers and aggregate operation over the current frame. Supports the timestamp-peer interpretation for the illustrated sums and means.
- [PT18]PostgreSQL 18: 3.5. Window FunctionsChecked 2026-10-21. Explains retained row identities, partitions and the distinction between window ordering and output ordering. Useful when interpreting a feature attached to each observation.
- [L1]Leviathan Systems: Structured Cabling & Fiber InstallationChecked 2026-10-21. Defines agreed physical fiber and copper installation, endpoint labels and connection records with identified material responsibilities. Relevant to a separate equipment-connection project.
08Related
Contact
Does the wider project also need physical cabling?
Share a nonconfidential equipment and site outline, required connections, material responsibilities and handoff needs to discuss physical installation scope and availability.