Skip to content

PostgreSQL, SQLite: Keep untyped string window frame offsets untyped - #2781

Open
LucaCappelletti94 wants to merge 6 commits into
mainfrom
window-frame-untyped-offset
Open

LucaCappelletti94 wants to merge 6 commits into
mainfrom
window-frame-untyped-offset

Conversation

@LucaCappelletti94

Copy link
Copy Markdown
Contributor

SELECT sum(x) OVER (ORDER BY f RANGE BETWEEN 'inf' PRECEDING AND '1 day' FOLLOWING) FROM t rendered with INTERVAL 'inf' PRECEDING AND INTERVAL '1 day' FOLLOWING in every dialect without require_interval_qualifier. PostgreSQL and SQLite take the type of an untyped offset from the ORDER BY column, so the added INTERVAL changes the statement.

The frame offset is now parsed with parse_expr, dropping the string special case added in #655. INTERVAL '1' DAY PRECEDING still parses as an interval. In the dialects that require an interval qualifier, '1' PRECEDING used to fail and now parses as a string, and '1' DAY PRECEDING without INTERVAL now fails.

https://www.postgresql.org/docs/current/sql-expressions.html#SYNTAX-WINDOW-FUNCTIONS and https://www.sqlite.org/windowfunctions.html#frame_boundaries

Yet another PR that has more PR text than code.

@LucaCappelletti94 LucaCappelletti94 added bug Something isn't working PostgreSQL SQLite labels Oct 31, 2026
@codecov-commenter

codecov-commenter commented Oct 31, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 83.30%. Comparing base (5201fb1) to head (3e189fb).

Files with missing lines Patch % Lines
src/parser/mod.rs 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2781      +/-   ##
==========================================
+ Coverage   83.29%   83.30%   +0.01%     
==========================================
  Files          42       42              
  Lines       35372    35375       +3     
  Branches    35372    35375       +3     
==========================================
+ Hits        29463    29470       +7     
+ Misses       2456     2455       -1     
+ Partials     3453     3450       -3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@LucaCappelletti94
LucaCappelletti94 force-pushed the window-frame-untyped-offset branch from fce98d0 to 52d27f6 Compare October 31, 2026 18:59
@LucaCappelletti94
LucaCappelletti94 force-pushed the window-frame-untyped-offset branch from 52d27f6 to 71f3777 Compare November 2, 2026 14:17
Comment thread src/parser/mod.rs
Token::SingleQuotedString(_) => self.parse_interval()?,
_ => self.parse_expr()?,
}))
Some(Box::new(self.parse_expr()?))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also rejects RANGE '1' DAY PRECEDING (unit, no INTERVAL keyword) in every dialect, Generic included: Expected: PRECEDING or FOLLOWING, found: DAY. DataFusion's window.slt uses '0' DAY FOLLOWING and '5' SECOND PRECEDING, and its planner only handles Expr::Interval or a number as a frame offset, so maybe keep the interval path when the string is followed by a temporal unit?

- `'0' DAY FOLLOWING` and `'5' SECOND PRECEDING` parse as intervals again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working PostgreSQL SQLite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants