diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 42e8ab3d33..64aa339da3 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -970,9 +970,10 @@ impl<'a> Parser<'a> { let arguments = match object_type { CommentObject::Function | CommentObject::Procedure | CommentObject::Aggregate => { if self.consume_token(&Token::LParen) { - let list = self.parse_comma_separated0(Self::parse_data_type, Token::RParen)?; + let args = + self.parse_comma_separated0(Self::parse_function_arg, Token::RParen)?; self.expect_token(&Token::RParen)?; - Some(list) + Some(args.into_iter().map(|a| a.data_type).collect()) } else { None } diff --git a/tests/sqlparser_postgres.rs b/tests/sqlparser_postgres.rs index 765fb97d77..12c4519b80 100644 --- a/tests/sqlparser_postgres.rs +++ b/tests/sqlparser_postgres.rs @@ -10677,6 +10677,46 @@ fn parse_comment_on_function_with_arg_types() { } } +#[test] +fn parse_comment_on_function_with_argname() { + pg_and_generic().one_statement_parses_to( + "COMMENT ON FUNCTION add(a INTEGER, b INTEGER) IS 'adds'", + "COMMENT ON FUNCTION add(INTEGER, INTEGER) IS 'adds'", + ); +} + +#[test] +fn parse_comment_on_function_with_argmode() { + pg_and_generic().one_statement_parses_to( + "COMMENT ON FUNCTION upsert(IN id INTEGER, OUT result TEXT) IS 'upserts'", + "COMMENT ON FUNCTION upsert(INTEGER, TEXT) IS 'upserts'", + ); + pg_and_generic().one_statement_parses_to( + "COMMENT ON FUNCTION swap(INOUT a INTEGER, INOUT b INTEGER) IS 'swap'", + "COMMENT ON FUNCTION swap(INTEGER, INTEGER) IS 'swap'", + ); +} + +#[test] +fn parse_comment_on_function_with_variadic() { + pg_and_generic().one_statement_parses_to( + "COMMENT ON FUNCTION concat_all(VARIADIC arr TEXT[]) IS 'joins'", + "COMMENT ON FUNCTION concat_all(TEXT[]) IS 'joins'", + ); +} + +#[test] +fn parse_comment_on_aggregate_with_argname_and_variadic() { + pg_and_generic().one_statement_parses_to( + "COMMENT ON AGGREGATE my_sum(val INTEGER) IS 'sums'", + "COMMENT ON AGGREGATE my_sum(INTEGER) IS 'sums'", + ); + pg_and_generic().one_statement_parses_to( + "COMMENT ON AGGREGATE concat_agg(VARIADIC arr TEXT[]) IS 'agg'", + "COMMENT ON AGGREGATE concat_agg(TEXT[]) IS 'agg'", + ); +} + #[test] fn parse_alter_type_add_attribute() { let sql = "ALTER TYPE public.my_type ADD ATTRIBUTE new_attr INTEGER";