Skip to content

PostgreSQL: COMMENT ON FUNCTION/PROCEDURE/AGGREGATE accepts argmode/argname/VARIADIC#28

Merged
fmguerreiro merged 1 commit intomainfrom
fix/comment-on-arg-modes
Apr 25, 2026
Merged

PostgreSQL: COMMENT ON FUNCTION/PROCEDURE/AGGREGATE accepts argmode/argname/VARIADIC#28
fmguerreiro merged 1 commit intomainfrom
fix/comment-on-arg-modes

Conversation

@fmguerreiro
Copy link
Copy Markdown
Owner

Bug

Parser::parse_comment parses the argument list for COMMENT ON FUNCTION / PROCEDURE / AGGREGATE using bare parse_data_type. PostgreSQL permits an argmode (IN / OUT / INOUT / VARIADIC) and an argname before the type — they are ignored for identity resolution, but they appear in real-world pg_dump output and in consumer-authored schema files. With the bare parse_data_type reader, all of these hard-fail today:

COMMENT ON FUNCTION add(a int, b int) IS '...';                   -- argname
COMMENT ON FUNCTION upsert(IN id int, OUT result text) IS '...';  -- modes
COMMENT ON FUNCTION concat_all(VARIADIC arr text[]) IS '...';     -- VARIADIC

Fix

Swap parse_data_type for parse_function_arg in the FUNCTION / PROCEDURE / AGGREGATE arms of parse_comment. parse_function_arg already consumes [mode] [name] type [DEFAULT expr]. Statement::Comment.arguments is Option<Vec<DataType>>, so we project with .into_iter().map(|a| a.data_type).collect() — the mode/name are intentionally discarded since they are not part of the function identity for COMMENT ON. Round-trip canonicalises to the bare-type form, matching the existing serializer.

No other call sites of parse_data_type are touched.

Tests

Added to tests/sqlparser_postgres.rs:

  • parse_comment_on_function_with_argnameadd(a INTEGER, b INTEGER) round-trips to bare types
  • parse_comment_on_function_with_argmodeIN/OUT/INOUT modes
  • parse_comment_on_function_with_variadicVARIADIC arr TEXT[]
  • parse_comment_on_aggregate_with_argname_and_variadic — same shapes for COMMENT ON AGGREGATE

Downstream

Unblocks pgmold's COMMENT ON AST migration, which currently rejects valid Postgres dumps containing these shapes.

Verification

Locally green:

  • cargo fmt --all
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo test --all-features
  • cargo check --no-default-features --target thumbv6m-none-eabi
  • (cd sqlparser_bench && cargo clippy --all-targets --all-features -- -D warnings)

…rgname/VARIADIC

Postgres permits argmode (IN/OUT/INOUT/VARIADIC) and argname tokens
ahead of each argument type in COMMENT ON FUNCTION / PROCEDURE /
AGGREGATE; they are ignored for identity resolution but appear in
real-world dumps and consumer schema files. The previous parser used
bare parse_data_type for the argument list, which hard-failed on those
shapes.

Switch the function-like arms of parse_comment to parse_function_arg
and project to data_type, since Statement::Comment.arguments stores a
plain Vec<DataType> and the modes/names are intentionally discarded
for identity matching.

Add tests covering argname, IN/OUT/INOUT, VARIADIC, and AGGREGATE.
@fmguerreiro fmguerreiro merged commit 2c3f3f1 into main Apr 25, 2026
19 checks passed
fmguerreiro added a commit that referenced this pull request Apr 26, 2026
Minor bump per the fork convention that any AST change warrants 0.(N+1).
Includes the breaking rename of Statement::Comment.relation -> table_name
(#31) plus #28 and #30 as fork-side work since the 0.61.0 release.
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