moshap-firebolt commented on code in PR #2614:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/2614#discussion_r4265890625


##########
src/parser/mod.rs:
##########
@@ -3431,14 +3440,30 @@ impl<'a> Parser<'a> {
         // to match the different flavours of INTERVAL syntax, we only allow 
expressions
         // if the dialect requires an interval qualifier,
         // see https://github.com/sqlparser-rs/sqlparser-rs/pull/1398 for more 
details
-        let value = if self.dialect.require_interval_qualifier() {
+        let literal_value = 
self.dialect.supports_interval_string_without_qualifier();
+        let value = if literal_value {
+            // otherwise `interval` is read as a name
+            self.parse_interval_literal_value()?
+        } else if self.dialect.require_interval_qualifier() {
             // parse a whole expression so `INTERVAL 1 + 1 DAY` is valid
             self.parse_expr()?
         } else {
             // parse a prefix expression so `INTERVAL 1 DAY` is valid, but 
`INTERVAL 1 + 1 DAY` is not
             // this also means that `INTERVAL '5 days' > INTERVAL '1 day'` 
treated properly
             self.parse_prefix()?
         };
+        // only an unsigned string may omit the qualifier
+        let qualifier_required = if literal_value {
+            !matches!(
+                &value,
+                Expr::Value(ValueWithSpan {
+                    value: Value::SingleQuotedString(_),

Review Comment:
   Done



##########
src/parser/mod.rs:
##########
@@ -3490,6 +3515,35 @@ impl<'a> Parser<'a> {
         }))
     }
 
+    /// A signed number or string literal.
+    fn parse_interval_literal_value(&mut self) -> Result<Expr, ParserError> {
+        let sign = match self.peek_token_ref().token {
+            Token::Plus => Some(UnaryOperator::Plus),
+            Token::Minus => Some(UnaryOperator::Minus),
+            _ => None,
+        };
+        if sign.is_some() {
+            self.advance_token();
+        }
+        let next = self.next_token();
+        let value = match next.token {
+            Token::Number(n, l) => {
+                Expr::value(Value::Number(Self::parse(n, next.span.start)?, 
l).with_span(next.span))
+            }
+            Token::SingleQuotedString(s) => {
+                Expr::value(Value::SingleQuotedString(s).with_span(next.span))
+            }

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to