You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by gi...@apache.org on 2026/10/18 10:08:08 UTC

(datafusion-sqlparser-rs) branch main updated: SQLite: Support a parenthesized table name in `FROM` (#2658)

This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new 4ad878405 SQLite: Support a parenthesized table name in `FROM` (#2658)
4ad878405 is described below

commit 4ad878405805b0a0c0df347acd91845c4745cff5
Author: Luca Cappelletti <ca...@gmail.com>
AuthorDate: Sun Oct 18 10:06:32 2026 +0000

    SQLite: Support a parenthesized table name in `FROM` (#2658)
---
 src/dialect/mod.rs        |  3 ++-
 src/dialect/sqlite.rs     |  4 ++++
 tests/sqlparser_sqlite.rs | 25 +++++++++++++++++++++++++
 3 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/src/dialect/mod.rs b/src/dialect/mod.rs
index f7c54a9b7..5997d7d30 100644
--- a/src/dialect/mod.rs
+++ b/src/dialect/mod.rs
@@ -1199,7 +1199,8 @@ pub trait Dialect: Debug + Any {
     /// SELECT * FROM (mytable) AS alias;
     /// ```
     ///
-    /// [Snowflake](https://docs.snowflake.com/en/sql-reference/constructs/from)
+    /// [Snowflake](https://docs.snowflake.com/en/sql-reference/constructs/from),
+    /// [SQLite](https://www.sqlite.org/syntax/table-or-subquery.html)
     fn supports_parens_around_table_factor(&self) -> bool {
         false
     }
diff --git a/src/dialect/sqlite.rs b/src/dialect/sqlite.rs
index 497639556..f63e4cbe1 100644
--- a/src/dialect/sqlite.rs
+++ b/src/dialect/sqlite.rs
@@ -142,4 +142,8 @@ impl Dialect for SQLiteDialect {
     fn supports_national_string_literal(&self) -> bool {
         false
     }
+
+    fn supports_parens_around_table_factor(&self) -> bool {
+        true
+    }
 }
diff --git a/tests/sqlparser_sqlite.rs b/tests/sqlparser_sqlite.rs
index ade2d9d82..2e60c75ef 100644
--- a/tests/sqlparser_sqlite.rs
+++ b/tests/sqlparser_sqlite.rs
@@ -1117,6 +1117,31 @@ fn parse_create_table_options_list() {
     }
 }
 
+#[test]
+fn parse_parenthesized_table_factor() {
+    for (sql, canonical) in [
+        ("SELECT * FROM (t)", "SELECT * FROM t"),
+        ("SELECT * FROM ((t))", "SELECT * FROM t"),
+        ("SELECT * FROM (t) AS a", "SELECT * FROM t AS a"),
+        ("SELECT * FROM (t AS a)", "SELECT * FROM t AS a"),
+        (
+            "SELECT * FROM ((SELECT 1) AS s)",
+            "SELECT * FROM (SELECT 1) AS s",
+        ),
+        ("SELECT * FROM f(), (t)", "SELECT * FROM f(), t"),
+    ] {
+        sqlite_and_generic().one_statement_parses_to(sql, canonical);
+    }
+
+    assert_eq!(
+        all_dialects_where(|d| !d.supports_parens_around_table_factor())
+            .parse_sql_statements("SELECT * FROM (t)"),
+        Err(ParserError::ParserError(
+            "Expected: joined table, found: )".to_string()
+        ))
+    );
+}
+
 fn sqlite() -> TestedDialects {
     TestedDialects::new(vec![Box::new(SQLiteDialect {})])
 }


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