diff --git a/src/ast/query.rs b/src/ast/query.rs index 34ad74da6..ad5727cef 100644 --- a/src/ast/query.rs +++ b/src/ast/query.rs @@ -524,12 +524,12 @@ impl fmt::Display for WildcardAdditionalOptions { #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "visitor", derive(Visit, VisitMut))] pub struct IlikeSelectItem { - pub pattern: Expr, + pub pattern: String, } impl fmt::Display for IlikeSelectItem { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "ILIKE {}", self.pattern)?; + write!(f, "ILIKE '{}'", self.pattern)?; Ok(()) } } diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 0515b1b60..26845978b 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -8818,10 +8818,8 @@ impl<'a> Parser<'a> { &mut self, ) -> Result, ParserError> { let opt_ilike = if self.parse_keyword(Keyword::ILIKE) { - let pattern = self.parse_value()?; - Some(IlikeSelectItem { - pattern: Expr::Value(pattern), - }) + let pattern = self.parse_literal_string()?; + Some(IlikeSelectItem { pattern }) } else { None }; diff --git a/tests/sqlparser_snowflake.rs b/tests/sqlparser_snowflake.rs index 135781fc4..ca8958fd4 100644 --- a/tests/sqlparser_snowflake.rs +++ b/tests/sqlparser_snowflake.rs @@ -1621,13 +1621,31 @@ fn test_select_wildcard_with_ilike() { let select = snowflake_and_generic().verified_only_select(r#"SELECT * ILIKE '%id%' FROM tbl"#); let expected = SelectItem::Wildcard(WildcardAdditionalOptions { opt_ilike: Some(IlikeSelectItem { - pattern: Expr::Value(Value::SingleQuotedString("%id%".to_owned())), + pattern: "%id%".to_owned(), }), ..Default::default() }); assert_eq!(expected, select.projection[0]); } +#[test] +fn test_select_wildcard_with_ilike_non_literal() { + let res = snowflake().parse_sql_statements(r#"SELECT * ILIKE %id FROM tbl"#); + assert_eq!( + res.unwrap_err().to_string(), + "sql parser error: Expected literal string, found: %" + ); +} + +#[test] +fn test_select_wildcard_with_ilike_number() { + let res = snowflake().parse_sql_statements(r#"SELECT * ILIKE 42 FROM tbl"#); + assert_eq!( + res.unwrap_err().to_string(), + "sql parser error: Expected literal string, found: 42" + ); +} + #[test] fn test_select_wildcard_with_ilike_replace() { let res = snowflake().parse_sql_statements(r#"SELECT * ILIKE '%id%' EXCLUDE col FROM tbl"#);