Skip to content

Support qualified column names in MATCH AGAINST clause #1774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ pub enum Expr {
/// [(1)]: https://dev.mysql.com/doc/refman/8.0/en/fulltext-search.html#function_match
MatchAgainst {
/// `(<col>, <col>, ...)`.
columns: Vec<Ident>,
columns: Vec<ObjectName>,
/// `<expr>`.
match_value: Value,
/// `<search modifier>`
Expand Down
2 changes: 1 addition & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2704,7 +2704,7 @@ impl<'a> Parser<'a> {
/// This method will raise an error if the column list is empty or with invalid identifiers,
/// the match expression is not a literal string, or if the search modifier is not valid.
pub fn parse_match_against(&mut self) -> Result<Expr, ParserError> {
let columns = self.parse_parenthesized_column_list(Mandatory, false)?;
let columns = self.parse_parenthesized_qualified_column_list(Mandatory, false)?;

self.expect_keyword_is(Keyword::AGAINST)?;

Expand Down
29 changes: 29 additions & 0 deletions tests/sqlparser_mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3454,3 +3454,32 @@ fn parse_cast_integers() {
.run_parser_method("CAST(foo AS UNSIGNED INTEGER(3))", |p| p.parse_expr())
.expect_err("CAST doesn't allow display width");
}

#[test]
fn parse_match_against_with_alias() {
let sql = "SELECT tbl.ProjectID FROM surveys.tbl1 AS tbl WHERE MATCH (tbl.ReferenceID) AGAINST ('AAA' IN BOOLEAN MODE)";
match mysql().verified_stmt(sql) {
Statement::Query(query) => match *query.body {
SetExpr::Select(select) => match select.selection {
Some(Expr::MatchAgainst {
columns,
match_value,
opt_search_modifier,
}) => {
assert_eq!(
columns,
vec![ObjectName::from(vec![
Ident::new("tbl"),
Ident::new("ReferenceID")
])]
);
assert_eq!(match_value, Value::SingleQuotedString("AAA".to_owned()));
assert_eq!(opt_search_modifier, Some(SearchModifier::InBooleanMode));
}
_ => unreachable!(),
},
_ => unreachable!(),
},
_ => unreachable!(),
}
}