@@ -1073,6 +1073,7 @@ impl<'a> Parser<'a> {
10731073 } ) )
10741074 }
10751075 Keyword :: NOT => self . parse_not ( ) ,
1076+
10761077 Keyword :: MATCH if dialect_of ! ( self is MySqlDialect | GenericDialect ) => {
10771078 self . parse_match_against ( )
10781079 }
@@ -1174,6 +1175,14 @@ impl<'a> Parser<'a> {
11741175 ) ,
11751176 } )
11761177 }
1178+ Token :: ExclamationMark if !self . dialect . supports_factorial_operator ( ) => {
1179+ Ok ( Expr :: UnaryOp {
1180+ op : UnaryOperator :: SpecialNot ,
1181+ expr : Box :: new (
1182+ self . parse_subexpr ( self . dialect . prec_value ( Precedence :: UnaryNot ) ) ?,
1183+ ) ,
1184+ } )
1185+ }
11771186 tok @ Token :: DoubleExclamationMark
11781187 | tok @ Token :: PGSquareRoot
11791188 | tok @ Token :: PGCubeRoot
@@ -1267,7 +1276,6 @@ impl<'a> Parser<'a> {
12671276 }
12681277 _ => self . expected ( "an expression" , next_token) ,
12691278 } ?;
1270-
12711279 if self . parse_keyword ( Keyword :: COLLATE ) {
12721280 Ok ( Expr :: Collate {
12731281 expr : Box :: new ( expr) ,
@@ -2024,6 +2032,13 @@ impl<'a> Parser<'a> {
20242032 }
20252033 }
20262034
2035+ pub fn parse_special_not ( & mut self ) -> Result < Expr , ParserError > {
2036+ Ok ( Expr :: UnaryOp {
2037+ op : UnaryOperator :: SpecialNot ,
2038+ expr : Box :: new ( self . parse_subexpr ( self . dialect . prec_value ( Precedence :: UnaryNot ) ) ?) ,
2039+ } )
2040+ }
2041+
20272042 /// Parses fulltext expressions [`sqlparser::ast::Expr::MatchAgainst`]
20282043 ///
20292044 /// # Errors
@@ -2797,8 +2812,27 @@ impl<'a> Parser<'a> {
27972812 } )
27982813 } else if Token :: ExclamationMark == tok {
27992814 // PostgreSQL factorial operation
2815+ match expr {
2816+ Expr :: Value ( _) | Expr :: Identifier ( _) => {
2817+ if !self . dialect . supports_factorial_operator ( ) {
2818+ return parser_err ! (
2819+ format!(
2820+ "current dialect: {:?} does not support factorial operator" ,
2821+ self . dialect
2822+ ) ,
2823+ self . peek_token( ) . location
2824+ ) ;
2825+ }
2826+ }
2827+ _ => { }
2828+ } ;
2829+ let op = if !self . dialect . supports_factorial_operator ( ) {
2830+ UnaryOperator :: SpecialNot
2831+ } else {
2832+ UnaryOperator :: PGPostfixFactorial
2833+ } ;
28002834 Ok ( Expr :: UnaryOp {
2801- op : UnaryOperator :: PGPostfixFactorial ,
2835+ op,
28022836 expr : Box :: new ( expr) ,
28032837 } )
28042838 } else if Token :: LBracket == tok {
0 commit comments