@@ -794,6 +794,7 @@ pub enum Statement {
794794 or_replace : bool ,
795795 temporary : bool ,
796796 external : bool ,
797+ global : Option < bool > ,
797798 if_not_exists : bool ,
798799 /// Table name
799800 name : ObjectName ,
@@ -812,6 +813,7 @@ pub enum Statement {
812813 engine : Option < String > ,
813814 default_charset : Option < String > ,
814815 collation : Option < String > ,
816+ on_commit : Option < OnCommit > ,
815817 } ,
816818 /// SQLite's `CREATE VIRTUAL TABLE .. USING <module_name> (<module_args>)`
817819 CreateVirtualTable {
@@ -1308,6 +1310,7 @@ impl fmt::Display for Statement {
13081310 hive_distribution,
13091311 hive_formats,
13101312 external,
1313+ global,
13111314 temporary,
13121315 file_format,
13131316 location,
@@ -1317,6 +1320,7 @@ impl fmt::Display for Statement {
13171320 default_charset,
13181321 engine,
13191322 collation,
1323+ on_commit,
13201324 } => {
13211325 // We want to allow the following options
13221326 // Empty column list, allowed by PostgreSQL:
@@ -1327,9 +1331,18 @@ impl fmt::Display for Statement {
13271331 // `CREATE TABLE t (a INT) AS SELECT a from t2`
13281332 write ! (
13291333 f,
1330- "CREATE {or_replace}{external}{temporary}TABLE {if_not_exists}{name}" ,
1334+ "CREATE {or_replace}{external}{global}{ temporary}TABLE {if_not_exists}{name}" ,
13311335 or_replace = if * or_replace { "OR REPLACE " } else { "" } ,
13321336 external = if * external { "EXTERNAL " } else { "" } ,
1337+ global = global
1338+ . map( |global| {
1339+ if global {
1340+ "GLOBAL "
1341+ } else {
1342+ "LOCAL "
1343+ }
1344+ } )
1345+ . unwrap_or( "" ) ,
13331346 if_not_exists = if * if_not_exists { "IF NOT EXISTS " } else { "" } ,
13341347 temporary = if * temporary { "TEMPORARY " } else { "" } ,
13351348 name = name,
@@ -1451,6 +1464,17 @@ impl fmt::Display for Statement {
14511464 if let Some ( collation) = collation {
14521465 write ! ( f, " COLLATE={}" , collation) ?;
14531466 }
1467+
1468+ if on_commit. is_some ( ) {
1469+ let on_commit = match on_commit {
1470+ Some ( OnCommit :: DeleteRows ) => "ON COMMIT DELETE ROWS" ,
1471+ Some ( OnCommit :: PreserveRows ) => "ON COMMIT PRESERVE ROWS" ,
1472+ Some ( OnCommit :: Drop ) => "ON COMMIT DROP" ,
1473+ None => "" ,
1474+ } ;
1475+ write ! ( f, " {}" , on_commit) ?;
1476+ }
1477+
14541478 Ok ( ( ) )
14551479 }
14561480 Statement :: CreateVirtualTable {
@@ -2351,6 +2375,14 @@ impl fmt::Display for CopyTarget {
23512375 }
23522376}
23532377
2378+ #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
2379+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
2380+ pub enum OnCommit {
2381+ DeleteRows ,
2382+ PreserveRows ,
2383+ Drop ,
2384+ }
2385+
23542386/// An option in `COPY` statement.
23552387///
23562388/// <https://www.postgresql.org/docs/14/sql-copy.html>
0 commit comments