PostgreSQL: add support for CREATE AGGREGATE#2316
Open
fmguerreiro wants to merge 9 commits intoapache:mainfrom
Open
PostgreSQL: add support for CREATE AGGREGATE#2316fmguerreiro wants to merge 9 commits intoapache:mainfrom
fmguerreiro wants to merge 9 commits intoapache:mainfrom
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.
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.
Summary
Adds PostgreSQL grammar for
CREATE [OR REPLACE] AGGREGATEwith the full option set from https://www.postgresql.org/docs/current/sql-createaggregate.html.What this supports
CREATE AGGREGATE name (arg_type [, ...]) (options)CREATE OR REPLACE AGGREGATESFUNC,STYPE,SSPACE,FINALFUNC,FINALFUNC_EXTRA,FINALFUNC_MODIFY,COMBINEFUNC,SERIALFUNC,DESERIALFUNC,INITCOND,MSFUNC,MINVFUNC,MSTYPE,MSSPACE,MFINALFUNC,MFINALFUNC_EXTRA,MFINALFUNC_MODIFY,MINITCOND,SORTOP,PARALLEL,HYPOTHETICALFINALFUNC_MODIFY/MFINALFUNC_MODIFYkinds:READ_ONLY,SHAREABLE,READ_WRITEChanges
CreateAggregatestruct plusCreateAggregateOptionandAggregateModifyKindenums insrc/ast/ddl.rswithfmt::Display+From<_> for Statement.Statement::CreateAggregatevariant and re-exports.Spannedarm usingSpan::empty().parse_create_aggregateinsrc/parser/mod.rs.OR REPLACE+PARALLEL, moving-aggregate options.Notes
Originally shipped via the
pgmold-sqlparserfork; tested against PostgreSQL 13–17 schemas in pgmold.