support create function definition with $$ (#755)

* support create function definition using '2700775'

* fix warn
This commit is contained in:
zidaye 2022-12-14 06:15:33 +08:00 committed by GitHub
parent d420001c37
commit 6c545195e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 91 additions and 10 deletions

View file

@ -2257,7 +2257,9 @@ fn parse_create_function() {
params: CreateFunctionBody {
language: Some("SQL".into()),
behavior: Some(FunctionBehavior::Immutable),
as_: Some("select $1 + $2;".into()),
as_: Some(FunctionDefinition::SingleQuotedDef(
"select $1 + $2;".into()
)),
..Default::default()
},
}
@ -2292,4 +2294,28 @@ fn parse_create_function() {
},
}
);
let sql = r#"CREATE OR REPLACE FUNCTION increment(i INTEGER) RETURNS INTEGER LANGUAGE plpgsql AS $$ BEGIN RETURN i + 1; END; $$"#;
assert_eq!(
pg().verified_stmt(sql),
Statement::CreateFunction {
or_replace: true,
temporary: false,
name: ObjectName(vec![Ident::new("increment")]),
args: Some(vec![CreateFunctionArg::with_name(
"i",
DataType::Integer(None)
)]),
return_type: Some(DataType::Integer(None)),
params: CreateFunctionBody {
language: Some("plpgsql".into()),
behavior: None,
return_: None,
as_: Some(FunctionDefinition::DoubleDollarDef(
" BEGIN RETURN i + 1; END; ".into()
)),
using: None
},
}
);
}