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/07/01 08:54:41 UTC

(datafusion-sqlparser-rs) branch gh-readonly-queue/main/pr-2251-eaf72313204a0b4348a8523814891005f150df35 created (now a023b78f)

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

github-merge-queue[bot] pushed a change to branch gh-readonly-queue/main/pr-2251-eaf72313204a0b4348a8523814891005f150df35
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git


      at a023b78f PostgreSQL `UNLOGGED` Table Support and `ALTER TABLE ... SET LOGGED|UNLOGGED` (#2251)

This branch includes the following new commits:

     new a023b78f PostgreSQL `UNLOGGED` Table Support and `ALTER TABLE ... SET LOGGED|UNLOGGED` (#2251)

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



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


(datafusion-sqlparser-rs) 01/01: PostgreSQL `UNLOGGED` Table Support and `ALTER TABLE ... SET LOGGED|UNLOGGED` (#2251)

Posted by gi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit a023b78f6908dd19436492850cfc66b083ba5b91
Author: Luca Cappelletti <ca...@gmail.com>
AuthorDate: Wed Jul 1 10:54:17 2026 +0200

    PostgreSQL `UNLOGGED` Table Support and `ALTER TABLE ... SET LOGGED|UNLOGGED` (#2251)
---
 src/ast/ddl.rs                       | 19 ++++++++-
 src/ast/helpers/stmt_create_table.rs | 10 +++++
 src/ast/spans.rs                     |  3 ++
 src/keywords.rs                      |  1 +
 src/parser/mod.rs                    | 17 +++++++-
 tests/sqlparser_common.rs            | 24 +++++++++++
 tests/sqlparser_duckdb.rs            |  1 +
 tests/sqlparser_mssql.rs             |  2 +
 tests/sqlparser_postgres.rs          | 79 ++++++++++++++++++++++++++++++++++++
 9 files changed, 153 insertions(+), 3 deletions(-)

diff --git a/src/ast/ddl.rs b/src/ast/ddl.rs
index 444fc1c0..346627c6 100644
--- a/src/ast/ddl.rs
+++ b/src/ast/ddl.rs
@@ -442,6 +442,14 @@ pub enum AlterTableOperation {
         /// Table properties specified as SQL options.
         table_properties: Vec<SqlOption>,
     },
+    /// `SET LOGGED`
+    ///
+    /// Note: this is PostgreSQL-specific.
+    SetLogged,
+    /// `SET UNLOGGED`
+    ///
+    /// Note: this is PostgreSQL-specific.
+    SetUnlogged,
     /// `OWNER TO { <new_owner> | CURRENT_ROLE | CURRENT_USER | SESSION_USER }`
     ///
     /// Note: this is PostgreSQL-specific <https://www.postgresql.org/docs/current/sql-altertable.html>
@@ -971,6 +979,12 @@ impl fmt::Display for AlterTableOperation {
                     display_comma_separated(table_properties)
                 )
             }
+            AlterTableOperation::SetLogged => {
+                write!(f, "SET LOGGED")
+            }
+            AlterTableOperation::SetUnlogged => {
+                write!(f, "SET UNLOGGED")
+            }
             AlterTableOperation::FreezePartition {
                 partition,
                 with_name,
@@ -2903,6 +2917,8 @@ pub struct CreateTable {
     pub or_replace: bool,
     /// `TEMP` or `TEMPORARY` clause
     pub temporary: bool,
+    /// `UNLOGGED` clause
+    pub unlogged: bool,
     /// `EXTERNAL` clause
     pub external: bool,
     /// `DYNAMIC` clause
@@ -3094,7 +3110,7 @@ impl fmt::Display for CreateTable {
         //   `CREATE TABLE t (a INT) AS SELECT a from t2`
         write!(
             f,
-            "CREATE {or_replace}{external}{global}{multiset}{temporary}{transient}{volatile}{dynamic}{iceberg}{snapshot}TABLE {if_not_exists}{name}",
+            "CREATE {or_replace}{external}{global}{multiset}{temporary}{unlogged}{transient}{volatile}{dynamic}{iceberg}{snapshot}TABLE {if_not_exists}{name}",
             or_replace = if self.or_replace { "OR REPLACE " } else { "" },
             external = if self.external { "EXTERNAL " } else { "" },
             snapshot = if self.snapshot { "SNAPSHOT " } else { "" },
@@ -3113,6 +3129,7 @@ impl fmt::Display for CreateTable {
                 .map(|m| if m { "MULTISET " } else { "SET " })
                 .unwrap_or(""),
             temporary = if self.temporary { "TEMPORARY " } else { "" },
+            unlogged = if self.unlogged { "UNLOGGED " } else { "" },
             transient = if self.transient { "TRANSIENT " } else { "" },
             volatile = if self.volatile { "VOLATILE " } else { "" },
             iceberg = if self.iceberg { "ICEBERG " } else { "" },
diff --git a/src/ast/helpers/stmt_create_table.rs b/src/ast/helpers/stmt_create_table.rs
index 9ec9ab28..84a93dd2 100644
--- a/src/ast/helpers/stmt_create_table.rs
+++ b/src/ast/helpers/stmt_create_table.rs
@@ -69,6 +69,8 @@ pub struct CreateTableBuilder {
     pub or_replace: bool,
     /// Whether the table is `TEMPORARY`.
     pub temporary: bool,
+    /// Whether the table is `UNLOGGED`.
+    pub unlogged: bool,
     /// Whether the table is `EXTERNAL`.
     pub external: bool,
     /// Optional `GLOBAL` flag for dialects that support it.
@@ -200,6 +202,7 @@ impl CreateTableBuilder {
         Self {
             or_replace: false,
             temporary: false,
+            unlogged: false,
             external: false,
             global: None,
             if_not_exists: false,
@@ -273,6 +276,11 @@ impl CreateTableBuilder {
         self.temporary = temporary;
         self
     }
+    /// Mark the table as `UNLOGGED`.
+    pub fn unlogged(mut self, unlogged: bool) -> Self {
+        self.unlogged = unlogged;
+        self
+    }
     /// Mark the table as `EXTERNAL`.
     pub fn external(mut self, external: bool) -> Self {
         self.external = external;
@@ -595,6 +603,7 @@ impl CreateTableBuilder {
         CreateTable {
             or_replace: self.or_replace,
             temporary: self.temporary,
+            unlogged: self.unlogged,
             external: self.external,
             global: self.global,
             if_not_exists: self.if_not_exists,
@@ -680,6 +689,7 @@ impl From<CreateTable> for CreateTableBuilder {
         Self {
             or_replace: table.or_replace,
             temporary: table.temporary,
+            unlogged: table.unlogged,
             external: table.external,
             global: table.global,
             if_not_exists: table.if_not_exists,
diff --git a/src/ast/spans.rs b/src/ast/spans.rs
index 7855ff15..6505b209 100644
--- a/src/ast/spans.rs
+++ b/src/ast/spans.rs
@@ -551,6 +551,7 @@ impl Spanned for CreateTable {
         let CreateTable {
             or_replace: _,    // bool
             temporary: _,     // bool
+            unlogged: _,      // bool
             external: _,      // bool
             global: _,        // bool
             dynamic: _,       // bool
@@ -1228,6 +1229,8 @@ impl Spanned for AlterTableOperation {
             AlterTableOperation::SetTblProperties { table_properties } => {
                 union_spans(table_properties.iter().map(|i| i.span()))
             }
+            AlterTableOperation::SetLogged => Span::empty(),
+            AlterTableOperation::SetUnlogged => Span::empty(),
             AlterTableOperation::OwnerTo { .. } => Span::empty(),
             AlterTableOperation::ClusterBy { exprs } => union_spans(exprs.iter().map(|e| e.span())),
             AlterTableOperation::DropClusteringKey => Span::empty(),
diff --git a/src/keywords.rs b/src/keywords.rs
index 0ff32948..c2d0a47e 100644
--- a/src/keywords.rs
+++ b/src/keywords.rs
@@ -601,6 +601,7 @@ define_keywords!(
     LOCK,
     LOCKED,
     LOG,
+    LOGGED,
     LOGIN,
     LOGS,
     LONG,
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index bd6334e4..d2fa9071 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -5231,6 +5231,10 @@ impl<'a> Parser<'a> {
             .parse_one_of_keywords(&[Keyword::TEMP, Keyword::TEMPORARY])
             .is_some();
         let volatile = self.parse_keyword(Keyword::VOLATILE);
+        let unlogged = self.peek_keywords(&[Keyword::UNLOGGED, Keyword::TABLE]);
+        if unlogged {
+            self.expect_keyword(Keyword::UNLOGGED)?;
+        }
         let persistent = dialect_of!(self is DuckDbDialect)
             && self.parse_one_of_keywords(&[Keyword::PERSISTENT]).is_some();
         let create_view_params = self.parse_create_view_params()?;
@@ -5239,8 +5243,10 @@ impl<'a> Parser<'a> {
         } else if self.peek_keywords(&[Keyword::TEXT, Keyword::SEARCH]) {
             self.parse_create_text_search().map(Into::into)
         } else if self.parse_keyword(Keyword::TABLE) {
-            self.parse_create_table(or_replace, temporary, global, transient, volatile, multiset)
-                .map(Into::into)
+            self.parse_create_table(
+                or_replace, temporary, unlogged, global, transient, volatile, multiset,
+            )
+            .map(Into::into)
         } else if self.peek_keyword(Keyword::MATERIALIZED)
             || self.peek_keyword(Keyword::VIEW)
             || self.peek_keywords(&[Keyword::SECURE, Keyword::MATERIALIZED, Keyword::VIEW])
@@ -8649,10 +8655,12 @@ impl<'a> Parser<'a> {
     }
 
     /// Parse `CREATE TABLE` statement.
+    #[allow(clippy::too_many_arguments)]
     pub fn parse_create_table(
         &mut self,
         or_replace: bool,
         temporary: bool,
+        unlogged: bool,
         global: Option<bool>,
         transient: bool,
         volatile: bool,
@@ -8834,6 +8842,7 @@ impl<'a> Parser<'a> {
 
         Ok(CreateTableBuilder::new(table_name)
             .temporary(temporary)
+            .unlogged(unlogged)
             .columns(columns)
             .constraints(constraints)
             .or_replace(or_replace)
@@ -11024,6 +11033,10 @@ impl<'a> Parser<'a> {
         } else if self.parse_keywords(&[Keyword::VALIDATE, Keyword::CONSTRAINT]) {
             let name = self.parse_identifier()?;
             AlterTableOperation::ValidateConstraint { name }
+        } else if self.parse_keywords(&[Keyword::SET, Keyword::LOGGED]) {
+            AlterTableOperation::SetLogged
+        } else if self.parse_keywords(&[Keyword::SET, Keyword::UNLOGGED]) {
+            AlterTableOperation::SetUnlogged
         } else {
             let mut options =
                 self.parse_options_with_keywords(&[Keyword::SET, Keyword::TBLPROPERTIES])?;
diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs
index f6f5fcdd..2af90809 100644
--- a/tests/sqlparser_common.rs
+++ b/tests/sqlparser_common.rs
@@ -19523,3 +19523,27 @@ fn parse_table_factor_paren_chain_no_exponential_blowup() {
     rx.recv_timeout(Duration::from_secs(5))
         .expect("parser should reject this quickly, not loop exponentially");
 }
+
+#[test]
+fn parse_unlogged_table_logging_controls_in_all_dialects() {
+    match all_dialects().verified_stmt("CREATE UNLOGGED TABLE t (a INT)") {
+        Statement::CreateTable(CreateTable { unlogged, .. }) => {
+            assert!(unlogged);
+        }
+        _ => unreachable!("Expected CREATE TABLE"),
+    }
+
+    match all_dialects().verified_stmt("ALTER TABLE t SET LOGGED") {
+        Statement::AlterTable(AlterTable { operations, .. }) => {
+            assert_eq!(vec![AlterTableOperation::SetLogged], operations);
+        }
+        _ => unreachable!("Expected ALTER TABLE"),
+    }
+
+    match all_dialects().verified_stmt("ALTER TABLE t SET UNLOGGED") {
+        Statement::AlterTable(AlterTable { operations, .. }) => {
+            assert_eq!(vec![AlterTableOperation::SetUnlogged], operations);
+        }
+        _ => unreachable!("Expected ALTER TABLE"),
+    }
+}
diff --git a/tests/sqlparser_duckdb.rs b/tests/sqlparser_duckdb.rs
index 86c76581..f8df4316 100644
--- a/tests/sqlparser_duckdb.rs
+++ b/tests/sqlparser_duckdb.rs
@@ -703,6 +703,7 @@ fn test_duckdb_union_datatype() {
         Statement::CreateTable(CreateTable {
             or_replace: Default::default(),
             temporary: Default::default(),
+            unlogged: Default::default(),
             external: Default::default(),
             global: Default::default(),
             if_not_exists: Default::default(),
diff --git a/tests/sqlparser_mssql.rs b/tests/sqlparser_mssql.rs
index 6e866746..3faf56f0 100644
--- a/tests/sqlparser_mssql.rs
+++ b/tests/sqlparser_mssql.rs
@@ -1924,6 +1924,7 @@ fn parse_create_table_with_valid_options() {
             Statement::CreateTable(CreateTable {
                 or_replace: false,
                 temporary: false,
+                unlogged: false,
                 external: false,
                 global: None,
                 dynamic: false,
@@ -2121,6 +2122,7 @@ fn parse_create_table_with_identity_column() {
             Statement::CreateTable(CreateTable {
                 or_replace: false,
                 temporary: false,
+                unlogged: false,
                 external: false,
                 global: None,
                 dynamic: false,
diff --git a/tests/sqlparser_postgres.rs b/tests/sqlparser_postgres.rs
index 2fa12574..19d89ad4 100644
--- a/tests/sqlparser_postgres.rs
+++ b/tests/sqlparser_postgres.rs
@@ -1278,6 +1278,33 @@ fn parse_alter_table_owner_to() {
     );
 }
 
+#[test]
+fn parse_alter_table_set_logged_unlogged() {
+    let sql = "ALTER TABLE unlogged1 SET LOGGED";
+    match pg_and_generic().verified_stmt(sql) {
+        Statement::AlterTable(AlterTable {
+            name, operations, ..
+        }) => {
+            assert_eq!("unlogged1", name.to_string());
+            assert_eq!(vec![AlterTableOperation::SetLogged], operations);
+        }
+        _ => unreachable!(),
+    }
+    pg_and_generic().one_statement_parses_to(sql, sql);
+
+    let sql = "ALTER TABLE unlogged1 SET UNLOGGED";
+    match pg_and_generic().verified_stmt(sql) {
+        Statement::AlterTable(AlterTable {
+            name, operations, ..
+        }) => {
+            assert_eq!("unlogged1", name.to_string());
+            assert_eq!(vec![AlterTableOperation::SetUnlogged], operations);
+        }
+        _ => unreachable!(),
+    }
+    pg_and_generic().one_statement_parses_to(sql, sql);
+}
+
 #[test]
 fn parse_create_table_if_not_exists() {
     let sql = "CREATE TABLE IF NOT EXISTS uk_cities ()";
@@ -5873,6 +5900,57 @@ fn parse_create_table_with_partition_by() {
     }
 }
 
+#[test]
+fn parse_create_unlogged_table() {
+    let sql = "CREATE UNLOGGED TABLE public.unlogged2 (a int primary key)";
+    match pg_and_generic().one_statement_parses_to(
+        sql,
+        "CREATE UNLOGGED TABLE public.unlogged2 (a INT PRIMARY KEY)",
+    ) {
+        Statement::CreateTable(CreateTable { name, unlogged, .. }) => {
+            assert!(unlogged);
+            assert_eq!("public.unlogged2", name.to_string());
+        }
+        _ => unreachable!(),
+    }
+
+    let sql = "CREATE UNLOGGED TABLE pg_temp.unlogged3 (a int primary key)";
+    match pg_and_generic().one_statement_parses_to(
+        sql,
+        "CREATE UNLOGGED TABLE pg_temp.unlogged3 (a INT PRIMARY KEY)",
+    ) {
+        Statement::CreateTable(CreateTable { name, unlogged, .. }) => {
+            assert!(unlogged);
+            assert_eq!("pg_temp.unlogged3", name.to_string());
+        }
+        _ => unreachable!(),
+    }
+
+    let sql = "CREATE UNLOGGED TABLE unlogged1 (a int) PARTITION BY RANGE (a)";
+    match pg_and_generic().one_statement_parses_to(
+        sql,
+        "CREATE UNLOGGED TABLE unlogged1 (a INT) PARTITION BY RANGE(a)",
+    ) {
+        Statement::CreateTable(CreateTable {
+            name,
+            unlogged,
+            partition_by,
+            ..
+        }) => {
+            assert!(unlogged);
+            assert_eq!("unlogged1", name.to_string());
+            assert!(partition_by.is_some());
+        }
+        _ => unreachable!(),
+    }
+
+    let res = pg().parse_sql_statements("CREATE UNLOGGED VIEW v AS SELECT 1");
+    assert_eq!(
+        ParserError::ParserError("Expected: an object type after CREATE, found: UNLOGGED".into()),
+        res.unwrap_err()
+    );
+}
+
 #[test]
 fn parse_join_constraint_unnest_alias() {
     assert_eq!(
@@ -6819,6 +6897,7 @@ fn parse_trigger_related_functions() {
         CreateTable {
             or_replace: false,
             temporary: false,
+            unlogged: false,
             external: false,
             global: None,
             dynamic: false,


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