@@ -1053,6 +1053,7 @@ impl<'a> Parser<'a> {
1053
1053
{
1054
1054
Ok(Some(Expr::Function(Function {
1055
1055
name: ObjectName(vec![w.to_ident(w_span)]),
1056
+ uses_odbc_syntax: false,
1056
1057
parameters: FunctionArguments::None,
1057
1058
args: FunctionArguments::None,
1058
1059
null_treatment: None,
@@ -1111,6 +1112,7 @@ impl<'a> Parser<'a> {
1111
1112
self.expect_token(&Token::RParen)?;
1112
1113
Ok(Some(Expr::Function(Function {
1113
1114
name: ObjectName(vec![w.to_ident(w_span)]),
1115
+ uses_odbc_syntax: false,
1114
1116
parameters: FunctionArguments::None,
1115
1117
args: FunctionArguments::Subquery(query),
1116
1118
filter: None,
@@ -1408,9 +1410,9 @@ impl<'a> Parser<'a> {
1408
1410
self.prev_token();
1409
1411
Ok(Expr::Value(self.parse_value()?))
1410
1412
}
1411
- Token::LBrace if self.dialect.supports_dictionary_syntax() => {
1413
+ Token::LBrace => {
1412
1414
self.prev_token();
1413
- self.parse_duckdb_struct_literal ()
1415
+ self.parse_lbrace_expr ()
1414
1416
}
1415
1417
_ => self.expected("an expression", next_token),
1416
1418
}?;
@@ -1509,23 +1511,46 @@ impl<'a> Parser<'a> {
1509
1511
}
1510
1512
}
1511
1513
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
+
1512
1532
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> {
1513
1537
self.expect_token(&Token::LParen)?;
1514
1538
1515
1539
// Snowflake permits a subquery to be passed as an argument without
1516
1540
// an enclosing set of parens if it's the only argument.
1517
1541
if dialect_of!(self is SnowflakeDialect) && self.peek_sub_query() {
1518
1542
let subquery = self.parse_query()?;
1519
1543
self.expect_token(&Token::RParen)?;
1520
- return Ok(Expr::Function( Function {
1544
+ return Ok(Function {
1521
1545
name,
1546
+ uses_odbc_syntax: false,
1522
1547
parameters: FunctionArguments::None,
1523
1548
args: FunctionArguments::Subquery(subquery),
1524
1549
filter: None,
1525
1550
null_treatment: None,
1526
1551
over: None,
1527
1552
within_group: vec![],
1528
- })) ;
1553
+ });
1529
1554
}
1530
1555
1531
1556
let mut args = self.parse_function_argument_list()?;
@@ -1584,15 +1609,16 @@ impl<'a> Parser<'a> {
1584
1609
None
1585
1610
};
1586
1611
1587
- Ok(Expr::Function( Function {
1612
+ Ok(Function {
1588
1613
name,
1614
+ uses_odbc_syntax: false,
1589
1615
parameters,
1590
1616
args: FunctionArguments::List(args),
1591
1617
null_treatment,
1592
1618
filter,
1593
1619
over,
1594
1620
within_group,
1595
- }))
1621
+ })
1596
1622
}
1597
1623
1598
1624
/// Optionally parses a null treatment clause.
@@ -1619,6 +1645,7 @@ impl<'a> Parser<'a> {
1619
1645
};
1620
1646
Ok(Expr::Function(Function {
1621
1647
name,
1648
+ uses_odbc_syntax: false,
1622
1649
parameters: FunctionArguments::None,
1623
1650
args,
1624
1651
filter: None,
@@ -2211,6 +2238,31 @@ impl<'a> Parser<'a> {
2211
2238
}
2212
2239
}
2213
2240
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
+
2214
2266
/// Parses fulltext expressions [`sqlparser::ast::Expr::MatchAgainst`]
2215
2267
///
2216
2268
/// # Errors
@@ -7578,6 +7630,7 @@ impl<'a> Parser<'a> {
7578
7630
} else {
7579
7631
Ok(Statement::Call(Function {
7580
7632
name: object_name,
7633
+ uses_odbc_syntax: false,
7581
7634
parameters: FunctionArguments::None,
7582
7635
args: FunctionArguments::None,
7583
7636
over: None,
0 commit comments