Skip to content

PostgreSQL: add support for CREATE AGGREGATE#2316

Open
fmguerreiro wants to merge 9 commits intoapache:mainfrom
fmguerreiro:upstream/create-aggregate
Open

PostgreSQL: add support for CREATE AGGREGATE#2316
fmguerreiro wants to merge 9 commits intoapache:mainfrom
fmguerreiro:upstream/create-aggregate

Conversation

@fmguerreiro
Copy link
Copy Markdown
Contributor

@fmguerreiro fmguerreiro commented Apr 18, 2026

Summary

Adds PostgreSQL grammar for CREATE [OR REPLACE] AGGREGATE with 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 AGGREGATE
  • Options: SFUNC, STYPE, SSPACE, FINALFUNC, FINALFUNC_EXTRA, FINALFUNC_MODIFY, COMBINEFUNC, SERIALFUNC, DESERIALFUNC, INITCOND, MSFUNC, MINVFUNC, MSTYPE, MSSPACE, MFINALFUNC, MFINALFUNC_EXTRA, MFINALFUNC_MODIFY, MINITCOND, SORTOP, PARALLEL, HYPOTHETICAL
  • FINALFUNC_MODIFY / MFINALFUNC_MODIFY kinds: READ_ONLY, SHAREABLE, READ_WRITE

Changes

  • CreateAggregate struct plus CreateAggregateOption and AggregateModifyKind enums in src/ast/ddl.rs with fmt::Display + From<_> for Statement.
  • New Statement::CreateAggregate variant and re-exports.
  • Spanned arm using Span::empty().
  • parse_create_aggregate in src/parser/mod.rs.
  • Three round-trip tests: basic form, OR REPLACE + PARALLEL, moving-aggregate options.

Notes

Originally shipped via the pgmold-sqlparser fork; tested against PostgreSQL 13–17 schemas in pgmold.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant