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

[PR] Postgres: Parse trailing asterisk after table name in FROM clause [datafusion-sqlparser-rs]

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

   Before this PR, PostgreSQL's `FROM tbl_name*` syntax (asterisk explicitly indicating that descendant tables should be included) failed to parse:
   
   ```sql
   SELECT * FROM tbl_name*
   ```
   
   This was already supported for `TRUNCATE TABLE name*` and `LOCK TABLE name*`, but not for regular `FROM` items.
   
   Docs: https://www.postgresql.org/docs/current/sql-select.html#SQL-FROM
   
   ## Fix
   - Added a `has_trailing_asterisk` field to `TableFactor::Table`, parsed the same way as the existing asterisk handling in `TRUNCATE`/`LOCK TABLE`.
   - Renamed the pre-existing `has_asterisk` fields on `TruncateTableTarget` and `LockTableTarget` to `has_trailing_asterisk` for naming consistency.
   
   This PR was created with AI assistance.


-- 
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] Postgres: Parse trailing asterisk after table name in FROM clause [datafusion-sqlparser-rs]

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


##########
src/ast/query.rs:
##########
@@ -2224,11 +2228,15 @@ impl fmt::Display for TableFactor {
                 json_path,
                 sample,
                 index_hints,
+                has_trailing_asterisk,
             } => {
                 name.fmt(f)?;
                 if let Some(json_path) = json_path {
                     json_path.fmt(f)?;
                 }
+                if *has_trailing_asterisk {
+                    write!(f, "*")?;
+                }

Review Comment:
   You should render the `*` before `json_path`, matching the parse order. On Snowflake and Redshift (`supports_partiql`), `SELECT * FROM t*[0]` renders as `SELECT * FROM t[0]*`, which fails to parse back with `Expected: end of statement, found: *`.
   
   ```suggestion
                   if *has_trailing_asterisk {
                       write!(f, "*")?;
                   }
                   if let Some(json_path) = json_path {
                       json_path.fmt(f)?;
                   }
   ```



##########
src/parser/mod.rs:
##########
@@ -16720,6 +16720,10 @@ impl<'a> Parser<'a> {
         } else {
             let name = self.parse_object_name(true)?;
 
+            // Postgres/Snowflake: `FROM tab*` explicitly includes descendant tables.
+            // https://www.postgresql.org/docs/current/sql-select.html#SQL-FROM
+            let has_trailing_asterisk = self.consume_token(&Token::Mul);

Review Comment:
   You could drop this comment. Snowflake's `FROM` grammar has no `tab*` form, and the `has_trailing_asterisk` field doc already links the Postgres reference.
   
   ```suggestion
               let has_trailing_asterisk = self.consume_token(&Token::Mul);
   ```



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