LucaCappelletti94 commented on code in PR #2494:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/2494#discussion_r4301995730


##########
tests/sqlparser_common.rs:
##########
@@ -8428,6 +8428,13 @@ fn parse_substring() {
     verified_stmt("SELECT SUBSTRING('foo' FROM 1 FOR 2) FROM t");
     verified_stmt("SELECT SUBSTR('foo' FROM 1 FOR 2) FROM t");
     verified_stmt("SELECT SUBSTR('foo', 1, 2) FROM t");
+    verified_stmt("SELECT SUBSTRING(a IS NULL FROM 1)");
+    verified_stmt("SELECT SUBSTRING(a LIKE 'x' FROM 1)");
+    verified_stmt("SELECT SUBSTRING('1' SIMILAR '_' ESCAPE '#')");
+    one_statement_parses_to(
+        "SELECT SUBSTRING('1' FOR 3 FROM 1)",
+        "SELECT SUBSTRING('1' FROM 1 FOR 3)",
+    );

Review Comment:
   You may want to pin the reversed order as a round trip. On the current head 
it fails with `left: "SELECT SUBSTRING('1' FOR 3 FROM 1)"`, `right: "SELECT 
SUBSTRING('1' FROM 1 FOR 3)"`.
   
   ```suggestion
       verified_stmt("SELECT SUBSTRING('1' FOR 3 FROM 1)");
   ```



##########
src/ast/mod.rs:
##########
@@ -1211,6 +1215,11 @@ pub enum Expr {
         /// true if the expression is represented using the `SUBSTR` shorthand
         /// This flag is used for formatting.
         shorthand: bool,
+
+        /// true if the expression uses the `SUBSTRING(expr SIMILAR pattern 
ESCAPE escape)` syntax,
+        /// in which case `substring_from` holds the pattern and 
`substring_for` holds the escape.
+        /// This flag is used for formatting.
+        similar: bool,

Review Comment:
   Would a single syntax enum be better here, replacing `special` and `similar` 
with one variant each for the comma, `FROM`/`FOR`, `FOR`/`FROM` and 
`SIMILAR`/`ESCAPE` forms? `SUBSTRING('1' FOR 3 FROM 1)` now prints as 
`SUBSTRING('1' FROM 1 FOR 3)`, which breaks the round trip the README promises, 
and a third flag for the order would leave combinations such as `special` with 
`similar` representable.



-- 
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