Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
40 changes: 40 additions & 0 deletions tests/sqlparser_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Loading