@@ -1053,6 +1053,7 @@ impl<'a> Parser<'a> {
10531053 {
10541054 Ok(Some(Expr::Function(Function {
10551055 name: ObjectName(vec![w.to_ident(w_span)]),
1056+ uses_odbc_syntax: false,
10561057 parameters: FunctionArguments::None,
10571058 args: FunctionArguments::None,
10581059 null_treatment: None,
@@ -1111,6 +1112,7 @@ impl<'a> Parser<'a> {
11111112 self.expect_token(&Token::RParen)?;
11121113 Ok(Some(Expr::Function(Function {
11131114 name: ObjectName(vec![w.to_ident(w_span)]),
1115+ uses_odbc_syntax: false,
11141116 parameters: FunctionArguments::None,
11151117 args: FunctionArguments::Subquery(query),
11161118 filter: None,
@@ -1408,9 +1410,9 @@ impl<'a> Parser<'a> {
14081410 self.prev_token();
14091411 Ok(Expr::Value(self.parse_value()?))
14101412 }
1411- Token::LBrace if self.dialect.supports_dictionary_syntax() => {
1413+ Token::LBrace => {
14121414 self.prev_token();
1413- self.parse_duckdb_struct_literal ()
1415+ self.parse_lbrace_expr ()
14141416 }
14151417 _ => self.expected("an expression", next_token),
14161418 }?;
@@ -1509,23 +1511,46 @@ impl<'a> Parser<'a> {
15091511 }
15101512 }
15111513
1514+ /// Tries to parse the body of an [ODBC function] call.
1515+ /// i.e. without the enclosing braces
1516+ ///
1517+ /// ```sql
1518+ /// fn myfunc(1,2,3)
1519+ /// ```
1520+ ///
1521+ /// [ODBC function]: https://learn.microsoft.com/en-us/sql/odbc/reference/develop-app/scalar-function-calls?view=sql-server-2017
1522+ fn maybe_parse_odbc_fn_body(&mut self) -> Result<Option<Expr>, ParserError> {
1523+ self.maybe_parse(|p| {
1524+ p.expect_keyword(Keyword::FN)?;
1525+ let fn_name = p.parse_object_name(false)?;
1526+ let mut fn_call = p.parse_function_call(fn_name)?;
1527+ fn_call.uses_odbc_syntax = true;
1528+ Ok(Expr::Function(fn_call))
1529+ })
1530+ }
1531+
15121532 pub fn parse_function(&mut self, name: ObjectName) -> Result<Expr, ParserError> {
1533+ self.parse_function_call(name).map(Expr::Function)
1534+ }
1535+
1536+ fn parse_function_call(&mut self, name: ObjectName) -> Result<Function, ParserError> {
15131537 self.expect_token(&Token::LParen)?;
15141538
15151539 // Snowflake permits a subquery to be passed as an argument without
15161540 // an enclosing set of parens if it's the only argument.
15171541 if dialect_of!(self is SnowflakeDialect) && self.peek_sub_query() {
15181542 let subquery = self.parse_query()?;
15191543 self.expect_token(&Token::RParen)?;
1520- return Ok(Expr::Function( Function {
1544+ return Ok(Function {
15211545 name,
1546+ uses_odbc_syntax: false,
15221547 parameters: FunctionArguments::None,
15231548 args: FunctionArguments::Subquery(subquery),
15241549 filter: None,
15251550 null_treatment: None,
15261551 over: None,
15271552 within_group: vec![],
1528- })) ;
1553+ });
15291554 }
15301555
15311556 let mut args = self.parse_function_argument_list()?;
@@ -1584,15 +1609,16 @@ impl<'a> Parser<'a> {
15841609 None
15851610 };
15861611
1587- Ok(Expr::Function( Function {
1612+ Ok(Function {
15881613 name,
1614+ uses_odbc_syntax: false,
15891615 parameters,
15901616 args: FunctionArguments::List(args),
15911617 null_treatment,
15921618 filter,
15931619 over,
15941620 within_group,
1595- }))
1621+ })
15961622 }
15971623
15981624 /// Optionally parses a null treatment clause.
@@ -1619,6 +1645,7 @@ impl<'a> Parser<'a> {
16191645 };
16201646 Ok(Expr::Function(Function {
16211647 name,
1648+ uses_odbc_syntax: false,
16221649 parameters: FunctionArguments::None,
16231650 args,
16241651 filter: None,
@@ -2211,6 +2238,31 @@ impl<'a> Parser<'a> {
22112238 }
22122239 }
22132240
2241+ /// Parse expression types that start with a left brace '{'.
2242+ /// Examples:
2243+ /// ```sql
2244+ /// -- Dictionary expr.
2245+ /// {'key1': 'value1', 'key2': 'value2'}
2246+ ///
2247+ /// -- Function call using the ODBC syntax.
2248+ /// { fn CONCAT('foo', 'bar') }
2249+ /// ```
2250+ fn parse_lbrace_expr(&mut self) -> Result<Expr, ParserError> {
2251+ let token = self.expect_token(&Token::LBrace)?;
2252+
2253+ if let Some(fn_expr) = self.maybe_parse_odbc_fn_body()? {
2254+ self.expect_token(&Token::RBrace)?;
2255+ return Ok(fn_expr);
2256+ }
2257+
2258+ if self.dialect.supports_dictionary_syntax() {
2259+ self.prev_token(); // Put back the '{'
2260+ return self.parse_duckdb_struct_literal();
2261+ }
2262+
2263+ self.expected("an expression", token)
2264+ }
2265+
22142266 /// Parses fulltext expressions [`sqlparser::ast::Expr::MatchAgainst`]
22152267 ///
22162268 /// # Errors
@@ -7578,6 +7630,7 @@ impl<'a> Parser<'a> {
75787630 } else {
75797631 Ok(Statement::Call(Function {
75807632 name: object_name,
7633+ uses_odbc_syntax: false,
75817634 parameters: FunctionArguments::None,
75827635 args: FunctionArguments::None,
75837636 over: None,
0 commit comments