Skip to content

Commit cc4703c

Browse files
tests(postgres): add CREATE FUNCTION RETURNS SETOF cases
Cover SETOF UUID function declarations for no-arg, parameterized, and array/unnest bodies, and assert return_type/language/behavior in the parsed AST.
1 parent 13822ab commit cc4703c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/sqlparser_postgres.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4642,6 +4642,31 @@ fn parse_create_function_detailed() {
46424642
);
46434643
}
46444644

4645+
#[test]
4646+
fn parse_create_function_returns_setof() {
4647+
let cases = [
4648+
"CREATE FUNCTION any_ids() RETURNS SETOF UUID LANGUAGE sql STABLE AS 'SELECT ''00000000-0000-0000-0000-000000000000''::uuid'",
4649+
"CREATE FUNCTION ids_for_user(p_user_id UUID) RETURNS SETOF UUID LANGUAGE sql STABLE AS 'SELECT p_user_id'",
4650+
"CREATE FUNCTION ids_from_array() RETURNS SETOF UUID LANGUAGE sql STABLE AS 'SELECT unnest(ARRAY[''00000000-0000-0000-0000-000000000000''::uuid])'",
4651+
];
4652+
4653+
for sql in cases {
4654+
match pg_and_generic().verified_stmt(sql) {
4655+
Statement::CreateFunction(CreateFunction {
4656+
return_type,
4657+
language,
4658+
behavior,
4659+
..
4660+
}) => {
4661+
assert_eq!(return_type, Some(DataType::SetOf(Box::new(DataType::Uuid))));
4662+
assert_eq!(language, Some(Ident::new("sql")));
4663+
assert_eq!(behavior, Some(FunctionBehavior::Stable));
4664+
}
4665+
_ => panic!("Expected CreateFunction"),
4666+
}
4667+
}
4668+
}
4669+
46454670
#[test]
46464671
fn parse_create_function_with_security() {
46474672
let sql =

0 commit comments

Comments
 (0)