Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/squawk_parser/src/generated/syntax_kind.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 18 additions & 4 deletions crates/squawk_parser/src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2165,6 +2165,7 @@ fn call_expr_args(p: &mut Parser<'_>, lhs: CompletedMarker) -> CompletedMarker {
fn opt_agg_clauses(p: &mut Parser<'_>) {
opt_within_clause(p);
opt_filter_clause(p);
opt_null_treatment(p);
opt_over_clause(p);
}

Expand All @@ -2181,13 +2182,10 @@ fn opt_filter_clause(p: &mut Parser<'_>) {
}

fn opt_over_clause(p: &mut Parser<'_>) {
if p.at(OVER_KW) || p.at(RESPECT_KW) || p.at(IGNORE_KW) {
if p.at(OVER_KW) {
// OVER window_name
// OVER ( window_definition )
let m = p.start();
if p.eat(RESPECT_KW) || p.eat(IGNORE_KW) {
p.expect(NULLS_KW);
}
p.expect(OVER_KW);
if p.eat(L_PAREN) {
window_spec(p);
Expand All @@ -2199,6 +2197,22 @@ fn opt_over_clause(p: &mut Parser<'_>) {
}
}

fn opt_null_treatment(p: &mut Parser<'_>) {
if !p.at(RESPECT_KW) && !p.at(IGNORE_KW) {
return;
}

let m = p.start();
let kind = if p.eat(RESPECT_KW) {
RESPECT_NULLS
} else {
p.bump(IGNORE_KW);
IGNORE_NULLS
};
p.expect(NULLS_KW);
m.complete(p, kind);
}

fn opt_within_clause(p: &mut Parser<'_>) {
if p.at(WITHIN_KW) {
let m = p.start();
Expand Down
124 changes: 112 additions & 12 deletions crates/squawk_syntax/src/ast/generated/nodes.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions crates/squawk_syntax/src/postgresql.ungram
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ ArgList =
| '(' ('distinct' | 'all')? args:(Arg (',' Arg)*)? ')'

CallExpr =
Expr ArgList WithinClause? FilterClause? OverClause?
Expr ArgList WithinClause? FilterClause? NullTreatment? OverClause?
| ExtractFn
| GraphTableFn
| JsonExistsFn
Expand Down Expand Up @@ -1728,7 +1728,17 @@ FilterClause =
'filter' '(' 'where' Expr ')'

OverClause =
(('respect' | 'ignore') 'nulls')? 'over' (NameRef | '(' WindowSpec? ')')
'over' (NameRef | '(' WindowSpec? ')')

NullTreatment =
IgnoreNulls
| RespectNulls

IgnoreNulls =
'ignore' 'nulls'

RespectNulls =
'respect' 'nulls'

WithinClause =
'within' 'group' '(' OrderByClause ')'
Expand Down
6 changes: 3 additions & 3 deletions postgres/kwlist.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// synced from:
// commit: 2c4bd2bf5700db98be0602854a8b7fa2c16b5f4a
// committed at: 2026-05-23T09:39:58+09:00
// file: https://github.com/postgres/postgres/blob/2c4bd2bf5700db98be0602854a8b7fa2c16b5f4a/src/include/parser/kwlist.h
// commit: 6468f7a853c3c75066410cfb54ecdb3050ec7132
// committed at: 2026-06-25T14:25:57-07:00
// file: https://github.com/postgres/postgres/blob/6468f7a853c3c75066410cfb54ecdb3050ec7132/src/include/parser/kwlist.h
//
// update via:
// cargo xtask sync-pg
Expand Down
21 changes: 16 additions & 5 deletions postgres/regression_suite/aggregates.sql
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,33 @@ SELECT covar_pop(1::float8,'inf'::float8), covar_samp(3::float8,'inf'::float8);
SELECT covar_pop(1::float8,'nan'::float8), covar_samp(3::float8,'nan'::float8);

-- check some cases that formerly had poor roundoff-error behavior
-- note: regr_r2() differs from corr() for a horizontal line, per spec
SELECT corr(0.09, g), regr_r2(0.09, g)
FROM generate_series(1, 30) g;
SELECT corr(g, 0.09), regr_r2(g, 0.09), regr_slope(g, 0.09), regr_intercept(g, 0.09)
FROM generate_series(1, 30) g;
SELECT corr(1.3 + g * 1e-16, 1.3 + g * 1e-16)
FROM generate_series(1, 3) g;
SELECT corr(1e-100 + g * 1e-105, 1e-100 + g * 1e-105)

-- check some cases that formerly suffered from internal overflow/underflow
SELECT corr(1e-100 + g * 1e-105, 1e-100 + g * 1e-105),
regr_r2(1e-100 + g * 1e-105, 1e-100 + g * 1e-105)
FROM generate_series(1, 3) g;
SELECT corr(1e-100 + g * 1e-105, 1e-100 + g * 1e-105)
SELECT corr(1e-100 + g * 1e-105, 1e-100 + g * 1e-105),
regr_r2(1e-100 + g * 1e-105, 1e-100 + g * 1e-105)
FROM generate_series(1, 30) g;
SELECT corr(1e100 + g * 1e95, 1e100 + g * 1e95),
regr_r2(1e100 + g * 1e95, 1e100 + g * 1e95)
FROM generate_series(1, 2) g;
SELECT regr_intercept(y, x) FROM (VALUES (-1e150, 0), (2e150, 3e150)) v(x, y);
SELECT regr_intercept(y, x) FROM (VALUES (-1e-131, 0), (2e-131, 3e-131)) v(x, y);

-- these examples pose definitional questions for NaN inputs,
-- which we resolve by saying that an all-NaN input column is not all equal
SELECT corr(g, 'NaN') FROM generate_series(1, 30) g;
SELECT corr(0.1, 'NaN') FROM generate_series(1, 30) g;
SELECT corr('NaN', 'NaN') FROM generate_series(1, 30) g;
SELECT corr(g, 'NaN'), regr_r2(g, 'NaN') FROM generate_series(1, 30) g;
SELECT corr(0.1, 'NaN'), regr_r2(0.1, 'NaN') FROM generate_series(1, 30) g;
SELECT corr('NaN', 0.1), regr_r2('NaN', 0.1) FROM generate_series(1, 30) g;
SELECT corr('NaN', 'NaN'), regr_r2('NaN', 'NaN') FROM generate_series(1, 30) g;

-- test accum and combine functions directly
CREATE TABLE regr_test (x float8, y float8);
Expand Down
Loading
Loading