@@ -4294,6 +4294,7 @@ $$"#;
42944294 behavior: None ,
42954295 called_on_null: None ,
42964296 parallel: None ,
4297+ security: None ,
42974298 function_body: Some ( CreateFunctionBody :: AsBeforeOptions {
42984299 body: Expr :: Value (
42994300 ( Value :: DollarQuotedString ( DollarQuotedString { value: "\n BEGIN\n IF str1 <> str2 THEN\n RETURN TRUE;\n ELSE\n RETURN FALSE;\n END IF;\n END;\n " . to_owned( ) , tag: None } ) ) . with_empty_span( )
@@ -4335,6 +4336,7 @@ $$"#;
43354336 behavior: None ,
43364337 called_on_null: None ,
43374338 parallel: None ,
4339+ security: None ,
43384340 function_body: Some ( CreateFunctionBody :: AsBeforeOptions {
43394341 body: Expr :: Value (
43404342 ( Value :: DollarQuotedString ( DollarQuotedString { value: "\n BEGIN\n IF int1 <> 0 THEN\n RETURN TRUE;\n ELSE\n RETURN FALSE;\n END IF;\n END;\n " . to_owned( ) , tag: None } ) ) . with_empty_span( )
@@ -4380,6 +4382,7 @@ $$"#;
43804382 behavior: None ,
43814383 called_on_null: None ,
43824384 parallel: None ,
4385+ security: None ,
43834386 function_body: Some ( CreateFunctionBody :: AsBeforeOptions {
43844387 body: Expr :: Value (
43854388 ( Value :: DollarQuotedString ( DollarQuotedString { value: "\n BEGIN\n IF a <> b THEN\n RETURN TRUE;\n ELSE\n RETURN FALSE;\n END IF;\n END;\n " . to_owned( ) , tag: None } ) ) . with_empty_span( )
@@ -4425,6 +4428,7 @@ $$"#;
44254428 behavior: None ,
44264429 called_on_null: None ,
44274430 parallel: None ,
4431+ security: None ,
44284432 function_body: Some ( CreateFunctionBody :: AsBeforeOptions {
44294433 body: Expr :: Value (
44304434 ( Value :: DollarQuotedString ( DollarQuotedString { value: "\n BEGIN\n IF int1 <> int2 THEN\n RETURN TRUE;\n ELSE\n RETURN FALSE;\n END IF;\n END;\n " . to_owned( ) , tag: None } ) ) . with_empty_span( )
@@ -4463,6 +4467,7 @@ $$"#;
44634467 behavior: None ,
44644468 called_on_null: None ,
44654469 parallel: None ,
4470+ security: None ,
44664471 function_body: Some ( CreateFunctionBody :: AsBeforeOptions {
44674472 body: Expr :: Value (
44684473 ( Value :: DollarQuotedString ( DollarQuotedString {
@@ -4504,6 +4509,7 @@ fn parse_create_function() {
45044509 behavior: Some ( FunctionBehavior :: Immutable ) ,
45054510 called_on_null: Some ( FunctionCalledOnNull :: Strict ) ,
45064511 parallel: Some ( FunctionParallel :: Safe ) ,
4512+ security: None ,
45074513 function_body: Some ( CreateFunctionBody :: AsBeforeOptions {
45084514 body: Expr :: Value (
45094515 ( Value :: SingleQuotedString ( "select $1 + $2;" . into( ) ) ) . with_empty_span( )
@@ -4562,6 +4568,7 @@ fn parse_create_function_c_with_module_pathname() {
45624568 behavior: Some ( FunctionBehavior :: Immutable ) ,
45634569 called_on_null: None ,
45644570 parallel: Some ( FunctionParallel :: Safe ) ,
4571+ security: None ,
45654572 function_body: Some ( CreateFunctionBody :: AsBeforeOptions {
45664573 body: Expr :: Value (
45674574 ( Value :: SingleQuotedString ( "MODULE_PATHNAME" . into( ) ) ) . with_empty_span( )
@@ -4674,6 +4681,59 @@ AS $$ BEGIN RETURN event; END; $$"#;
46744681 }
46754682}
46764683
4684+ #[ test]
4685+ fn parse_create_function_with_security_definer ( ) {
4686+ let sql = r#"CREATE FUNCTION public.my_func() RETURNS void LANGUAGE sql SECURITY DEFINER AS $$ SELECT 1 $$"# ;
4687+
4688+ let stmt = pg ( ) . verified_stmt ( sql) ;
4689+ match stmt {
4690+ Statement :: CreateFunction ( CreateFunction { name, security, .. } ) => {
4691+ assert_eq ! ( name. to_string( ) , "public.my_func" ) ;
4692+ assert_eq ! ( security, Some ( FunctionSecurity :: Definer ) ) ;
4693+ }
4694+ _ => panic ! ( "Expected CreateFunction" ) ,
4695+ }
4696+ }
4697+
4698+ #[ test]
4699+ fn parse_create_function_with_security_invoker ( ) {
4700+ let sql = r#"CREATE FUNCTION public.my_func() RETURNS void LANGUAGE sql SECURITY INVOKER AS $$ SELECT 1 $$"# ;
4701+
4702+ let stmt = pg ( ) . verified_stmt ( sql) ;
4703+ match stmt {
4704+ Statement :: CreateFunction ( CreateFunction { name, security, .. } ) => {
4705+ assert_eq ! ( name. to_string( ) , "public.my_func" ) ;
4706+ assert_eq ! ( security, Some ( FunctionSecurity :: Invoker ) ) ;
4707+ }
4708+ _ => panic ! ( "Expected CreateFunction" ) ,
4709+ }
4710+ }
4711+
4712+ #[ test]
4713+ fn parse_create_function_with_security_and_other_attributes ( ) {
4714+ pg ( ) . one_statement_parses_to (
4715+ r#"CREATE FUNCTION test_func() RETURNS integer LANGUAGE plpgsql IMMUTABLE SECURITY DEFINER AS $$ BEGIN RETURN 42; END; $$"# ,
4716+ r#"CREATE FUNCTION test_func() RETURNS INTEGER LANGUAGE plpgsql IMMUTABLE SECURITY DEFINER AS $$ BEGIN RETURN 42; END; $$"# ,
4717+ ) ;
4718+
4719+ let stmt = pg ( ) . verified_stmt ( r#"CREATE FUNCTION test_func() RETURNS INTEGER LANGUAGE plpgsql IMMUTABLE SECURITY DEFINER AS $$ BEGIN RETURN 42; END; $$"# ) ;
4720+ match stmt {
4721+ Statement :: CreateFunction ( CreateFunction {
4722+ name,
4723+ security,
4724+ behavior,
4725+ language,
4726+ ..
4727+ } ) => {
4728+ assert_eq ! ( name. to_string( ) , "test_func" ) ;
4729+ assert_eq ! ( security, Some ( FunctionSecurity :: Definer ) ) ;
4730+ assert_eq ! ( behavior, Some ( FunctionBehavior :: Immutable ) ) ;
4731+ assert_eq ! ( language. as_ref( ) . map( |i| i. value. as_str( ) ) , Some ( "plpgsql" ) ) ;
4732+ }
4733+ _ => panic ! ( "Expected CreateFunction" ) ,
4734+ }
4735+ }
4736+
46774737#[ test]
46784738fn parse_drop_function ( ) {
46794739 let sql = "DROP FUNCTION IF EXISTS test_func" ;
@@ -6275,6 +6335,7 @@ fn parse_trigger_related_functions() {
62756335 behavior: None ,
62766336 called_on_null: None ,
62776337 parallel: None ,
6338+ security: None ,
62786339 using: None ,
62796340 language: Some ( Ident :: new( "plpgsql" ) ) ,
62806341 determinism_specifier: None ,
0 commit comments