PostgreSQL: add support for CREATE AGGREGATE#2316
Open
fmguerreiro wants to merge 14 commits into
Open
Conversation
Add Statement::CreateAggregate, CreateAggregate struct, CreateAggregateOption enum, and AggregateModifyKind enum to represent PostgreSQL CREATE AGGREGATE DDL. Options are stored as a typed enum covering all documented parameters (SFUNC, STYPE, FINALFUNC, PARALLEL, moving-aggregate variants, etc.).
Wire AGGREGATE into the CREATE dispatch (before the or_replace error branch so CREATE OR REPLACE AGGREGATE is accepted). parse_create_aggregate parses the name, argument-type list, and the options block. Each recognised option keyword dispatches to parse_create_aggregate_option which produces the typed CreateAggregateOption variant.
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.
PR #7 added the Statement::CreateAggregate variant but omitted the corresponding match arm in the Spanned impl for Statement. Fork CI never ran on the PR so this was not caught before merge.
- SORTOP now parses via parse_operator_name so bare operators (SORTOP = <) work correctly. - INITCOND / MINITCOND now store ValueWithSpan, preserving source location and matching the rest of the DDL layer. - Replace the hand-rolled option loop with parse_comma_separated, rejecting leading and doubled commas. - Simplify empty arg-list detection (no more prev_token dance). - Replace the PARALLEL match-with-fallthrough with the if/else-if shape used elsewhere in the parser. - Extend the 'after CREATE OR REPLACE' error message to mention AGGREGATE.
Return the name's span instead of Span::empty() to match the sibling Create* arms.
- Rename abbreviated CreateAggregateOption variants to full words - Preserve (*) wildcard arg list via CreateAggregate::star_args - Implement Spanned for CreateAggregate and delegate from Statement - Parse aggregate args as OperateFunctionArg so VARIADIC/named args round-trip instead of being dropped - Add verified_stmt coverage for HYPOTHETICAL, SORTOP, schema-qualified SORTOP, FINALFUNC_MODIFY, SSPACE, COMBINEFUNC, SERIALFUNC/DESERIALFUNC, star args, and named/variadic args - Switch CREATE AGGREGATE tests to pg_and_generic(), use display_comma_separated for options, extract parse_function_parallel
- Replace em-dashes in CreateAggregateOption doc comments - Add FunctionParallel::as_str and reuse it in Display and the PARALLEL option - Support old-syntax BASETYPE option (parse and Display round-trip) - Clarify the CreateAggregate args field doc - Test the unknown-option error path and the old BASETYPE syntax
…gate # Conflicts: # src/ast/mod.rs # tests/sqlparser_postgres.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Parses PostgreSQL
CREATE [OR REPLACE] AGGREGATE, both the modernname (arg_types) (options)form and the legacyBASETYPE = ...form.The full option set from the docs is covered: state and final functions, the moving-aggregate variants (
MSFUNC,MINVFUNC, ...),PARALLEL,SORTOP,HYPOTHETICAL, and theFINALFUNC_MODIFYkinds (READ_ONLY/SHAREABLE/READ_WRITE).parse_create_aggregatedispatches modern vs legacy on whether the option list opens withBASETYPE, building a newCreateAggregatenode behindStatement::CreateAggregate. Round-trip tests cover both syntaxes, star and variadic args, the moving-aggregate options, and an unknown-option error.Ordered-set aggregates (
ORDER BYin the argument list) are out of scope to keep this reviewable.Ported from the
pgmold-sqlparserfork, where it was tested against PostgreSQL 13-17 schemas in pgmold.