Skip to content

Commit aff2e81

Browse files
committed
test: add CREATE AGGREGATE round-trip tests
Three tests covering: basic old-style aggregate (SFUNC/STYPE/FINALFUNC/INITCOND), CREATE OR REPLACE with PARALLEL = SAFE, and moving-aggregate options (MSFUNC/MINVFUNC/MSTYPE/MFINALFUNC_EXTRA/MFINALFUNC_MODIFY). All use pg().verified_stmt() to assert parse-then-display round-trips identically.
1 parent 7f7ac31 commit aff2e81

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

tests/sqlparser_postgres.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9327,3 +9327,63 @@ fn parse_lock_table() {
93279327
}
93289328
}
93299329
}
9330+
9331+
#[test]
9332+
fn parse_create_aggregate_basic() {
9333+
let sql = "CREATE AGGREGATE myavg (NUMERIC) (SFUNC = numeric_avg_accum, STYPE = internal, FINALFUNC = numeric_avg, INITCOND = '0')";
9334+
let stmt = pg().verified_stmt(sql);
9335+
match stmt {
9336+
Statement::CreateAggregate(agg) => {
9337+
assert!(!agg.or_replace);
9338+
assert_eq!(agg.name.to_string(), "myavg");
9339+
assert_eq!(agg.args.len(), 1);
9340+
assert_eq!(agg.args[0].to_string(), "NUMERIC");
9341+
assert_eq!(agg.options.len(), 4);
9342+
assert_eq!(
9343+
agg.options[0].to_string(),
9344+
"SFUNC = numeric_avg_accum"
9345+
);
9346+
assert_eq!(agg.options[1].to_string(), "STYPE = internal");
9347+
assert_eq!(agg.options[2].to_string(), "FINALFUNC = numeric_avg");
9348+
assert_eq!(agg.options[3].to_string(), "INITCOND = '0'");
9349+
}
9350+
_ => panic!("Expected CreateAggregate, got: {stmt:?}"),
9351+
}
9352+
}
9353+
9354+
#[test]
9355+
fn parse_create_aggregate_or_replace_with_parallel() {
9356+
let sql = "CREATE OR REPLACE AGGREGATE sum2 (INT4, INT4) (SFUNC = int4pl, STYPE = INT4, PARALLEL = SAFE)";
9357+
let stmt = pg().verified_stmt(sql);
9358+
match stmt {
9359+
Statement::CreateAggregate(agg) => {
9360+
assert!(agg.or_replace);
9361+
assert_eq!(agg.name.to_string(), "sum2");
9362+
assert_eq!(agg.args.len(), 2);
9363+
assert_eq!(agg.options.len(), 3);
9364+
assert_eq!(agg.options[2].to_string(), "PARALLEL = SAFE");
9365+
}
9366+
_ => panic!("Expected CreateAggregate, got: {stmt:?}"),
9367+
}
9368+
}
9369+
9370+
#[test]
9371+
fn parse_create_aggregate_with_moving_aggregate_options() {
9372+
let sql = "CREATE AGGREGATE moving_sum (FLOAT8) (SFUNC = float8pl, STYPE = FLOAT8, MSFUNC = float8pl, MINVFUNC = float8mi, MSTYPE = FLOAT8, MFINALFUNC_EXTRA, MFINALFUNC_MODIFY = READ_ONLY)";
9373+
let stmt = pg().verified_stmt(sql);
9374+
match stmt {
9375+
Statement::CreateAggregate(agg) => {
9376+
assert!(!agg.or_replace);
9377+
assert_eq!(agg.name.to_string(), "moving_sum");
9378+
assert_eq!(agg.args.len(), 1);
9379+
assert_eq!(agg.options.len(), 7);
9380+
assert_eq!(agg.options[4].to_string(), "MSTYPE = FLOAT8");
9381+
assert_eq!(agg.options[5].to_string(), "MFINALFUNC_EXTRA");
9382+
assert_eq!(
9383+
agg.options[6].to_string(),
9384+
"MFINALFUNC_MODIFY = READ_ONLY"
9385+
);
9386+
}
9387+
_ => panic!("Expected CreateAggregate, got: {stmt:?}"),
9388+
}
9389+
}

0 commit comments

Comments
 (0)