@@ -4441,7 +4441,7 @@ $$"#;
44414441 DataType :: Varchar ( None ) ,
44424442 ) ,
44434443 ] ) ,
4444- return_type: Some ( DataType :: Boolean ) ,
4444+ return_type: Some ( FunctionReturnType :: DataType ( DataType :: Boolean ) ) ,
44454445 language: Some ( "plpgsql" . into( ) ) ,
44464446 behavior: None ,
44474447 called_on_null: None ,
@@ -4484,7 +4484,7 @@ $$"#;
44844484 DataType :: Int ( None )
44854485 )
44864486 ] ) ,
4487- return_type: Some ( DataType :: Boolean ) ,
4487+ return_type: Some ( FunctionReturnType :: DataType ( DataType :: Boolean ) ) ,
44884488 language: Some ( "plpgsql" . into( ) ) ,
44894489 behavior: None ,
44904490 called_on_null: None ,
@@ -4531,7 +4531,7 @@ $$"#;
45314531 DataType :: Int ( None )
45324532 ) ,
45334533 ] ) ,
4534- return_type: Some ( DataType :: Boolean ) ,
4534+ return_type: Some ( FunctionReturnType :: DataType ( DataType :: Boolean ) ) ,
45354535 language: Some ( "plpgsql" . into( ) ) ,
45364536 behavior: None ,
45374537 called_on_null: None ,
@@ -4578,7 +4578,7 @@ $$"#;
45784578 DataType :: Int ( None )
45794579 ) ,
45804580 ] ) ,
4581- return_type: Some ( DataType :: Boolean ) ,
4581+ return_type: Some ( FunctionReturnType :: DataType ( DataType :: Boolean ) ) ,
45824582 language: Some ( "plpgsql" . into( ) ) ,
45834583 behavior: None ,
45844584 called_on_null: None ,
@@ -4618,7 +4618,7 @@ $$"#;
46184618 ) ,
46194619 OperateFunctionArg :: with_name( "b" , DataType :: Varchar ( None ) ) ,
46204620 ] ) ,
4621- return_type: Some ( DataType :: Boolean ) ,
4621+ return_type: Some ( FunctionReturnType :: DataType ( DataType :: Boolean ) ) ,
46224622 language: Some ( "plpgsql" . into( ) ) ,
46234623 behavior: None ,
46244624 called_on_null: None ,
@@ -4661,7 +4661,7 @@ fn parse_create_function() {
46614661 OperateFunctionArg :: unnamed( DataType :: Integer ( None ) ) ,
46624662 OperateFunctionArg :: unnamed( DataType :: Integer ( None ) ) ,
46634663 ] ) ,
4664- return_type: Some ( DataType :: Integer ( None ) ) ,
4664+ return_type: Some ( FunctionReturnType :: DataType ( DataType :: Integer ( None ) ) ) ,
46654665 language: Some ( "SQL" . into( ) ) ,
46664666 behavior: Some ( FunctionBehavior :: Immutable ) ,
46674667 called_on_null: Some ( FunctionCalledOnNull :: Strict ) ,
@@ -4698,6 +4698,30 @@ fn parse_create_function_detailed() {
46984698 ) ;
46994699}
47004700
4701+ #[ test]
4702+ fn parse_create_function_returns_setof ( ) {
4703+ pg_and_generic ( ) . verified_stmt (
4704+ "CREATE FUNCTION get_users() RETURNS SETOF TEXT LANGUAGE sql AS 'SELECT name FROM users'" ,
4705+ ) ;
4706+ pg_and_generic ( ) . verified_stmt (
4707+ "CREATE FUNCTION get_ids() RETURNS SETOF INTEGER LANGUAGE sql AS 'SELECT id FROM users'" ,
4708+ ) ;
4709+ pg_and_generic ( ) . verified_stmt (
4710+ r#"CREATE FUNCTION get_all() RETURNS SETOF my_schema."MyType" LANGUAGE sql AS 'SELECT * FROM t'"# ,
4711+ ) ;
4712+ pg_and_generic ( ) . verified_stmt (
4713+ "CREATE FUNCTION get_rows() RETURNS SETOF RECORD LANGUAGE sql AS 'SELECT * FROM t'" ,
4714+ ) ;
4715+
4716+ let sql = "CREATE FUNCTION get_names() RETURNS SETOF TEXT LANGUAGE sql AS 'SELECT name FROM t'" ;
4717+ match pg_and_generic ( ) . verified_stmt ( sql) {
4718+ Statement :: CreateFunction ( CreateFunction { return_type, .. } ) => {
4719+ assert_eq ! ( return_type, Some ( FunctionReturnType :: SetOf ( DataType :: Text ) ) ) ;
4720+ }
4721+ _ => panic ! ( "Expected CreateFunction" ) ,
4722+ }
4723+ }
4724+
47014725#[ test]
47024726fn parse_create_function_with_security ( ) {
47034727 let sql =
@@ -4773,10 +4797,10 @@ fn parse_create_function_c_with_module_pathname() {
47734797 "input" ,
47744798 DataType :: Custom ( ObjectName :: from( vec![ Ident :: new( "cstring" ) ] ) , vec![ ] ) ,
47754799 ) , ] ) ,
4776- return_type: Some ( DataType :: Custom (
4800+ return_type: Some ( FunctionReturnType :: DataType ( DataType :: Custom (
47774801 ObjectName :: from( vec![ Ident :: new( "cas" ) ] ) ,
47784802 vec![ ]
4779- ) ) ,
4803+ ) ) ) ,
47804804 language: Some ( "c" . into( ) ) ,
47814805 behavior: Some ( FunctionBehavior :: Immutable ) ,
47824806 called_on_null: None ,
@@ -6493,7 +6517,7 @@ fn parse_trigger_related_functions() {
64936517 if_not_exists: false ,
64946518 name: ObjectName :: from( vec![ Ident :: new( "emp_stamp" ) ] ) ,
64956519 args: Some ( vec![ ] ) ,
6496- return_type: Some ( DataType :: Trigger ) ,
6520+ return_type: Some ( FunctionReturnType :: DataType ( DataType :: Trigger ) ) ,
64976521 function_body: Some (
64986522 CreateFunctionBody :: AsBeforeOptions {
64996523 body: Expr :: Value ( (
0 commit comments