You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "LucaCappelletti94 (via GitHub)" <gi...@apache.org> on 2026/09/22 07:36:09 UTC

[PR] Fix `TABLE` command identifier quoting and token consumption [datafusion-sqlparser-rs]

LucaCappelletti94 opened a new pull request, #2540:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/2540

   This PR changes `Table` fields from `Option<String>` to `Option<Ident>` and updates [`TABLE` command](https://www.postgresql.org/docs/current/sql-select.html#SQL-TABLE) parsing to preserve identifier quoting and stop eagerly consuming trailing tokens.
   
   Previously, `parse_as_table` discarded quote styles on table identifiers and unconditionally called `next_token()` three times, breaking roundtripping and trailing clauses:
   
   ```sql
   -- Quoted table names had quotes stripped on display, breaking re-parse:
   CREATE TABLE t AS TABLE `%mpty`;
   -- Displayed as:  CREATE TABLE t AS TABLE %mpty
   -- Re-parse error: ParserError("Expected: Table name, found: % at Line: 1, Column: 25")
   
   -- Trailing clauses were swallowed:
   CREATE TABLE t AS TABLE old_table ORDER BY x;
   -- Parse error: ParserError("Expected: end of statement, found: x")


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix `TABLE` command identifier quoting and token consumption [datafusion-sqlparser-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #2540:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/2540#discussion_r4073854275


##########
src/parser/mod.rs:
##########
@@ -15625,44 +15625,16 @@ impl<'a> Parser<'a> {
 
     /// Parse `CREATE TABLE x AS TABLE y`
     pub fn parse_as_table(&mut self) -> Result<Table, ParserError> {
-        let token1 = self.next_token();
-        let token2 = self.next_token();
-        let token3 = self.next_token();
-
-        let table_name;
-        let schema_name;
-        if token2 == Token::Period {
-            match token1.token {
-                Token::Word(w) => {
-                    schema_name = w.value;
-                }
-                _ => {
-                    return self.expected("Schema name", token1);
-                }
-            }
-            match token3.token {
-                Token::Word(w) => {
-                    table_name = w.value;
-                }
-                _ => {
-                    return self.expected("Table name", token3);
-                }
-            }
+        let first_name = self.parse_identifier()?;
+        if self.consume_token(&Token::Period) {
+            let second_name = self.parse_identifier()?;

Review Comment:
   fixing bugs and deleting code is level 10 coding 👍 



-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Fix `TABLE` command identifier quoting and token consumption [datafusion-sqlparser-rs]

Posted by "LucaCappelletti94 (via GitHub)" <gi...@apache.org>.
LucaCappelletti94 merged PR #2540:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/2540


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org