25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(duplicate): use boolean false predicate in fallback clone DDL
zipgf65249119843
diff --git a/crates/dbx-sql/src/db_admin_sql.rs b/crates/dbx-sql/src/db_admin_sql.rsindex d81009268f..b303a538a0 100644--- a/crates/dbx-sql/src/db_admin_sql.rs+++ b/crates/dbx-sql/src/db_admin_sql.rs@@ -798,7 +798,12 @@ pub fn build_duplicate_table_structure_sql(options: DuplicateTableStructureSqlOp} else if options.database_type.is_some_and(uses_false_predicate_duplicate_structure) {format!("CREATE TABLE {target} AS SELECT * FROM {source} WHERE 1=0")} else {- format!("CREATE TABLE {target} AS SELECT * FROM {source} WHERE 0;")+ // `WHERE 1=0` rather than `WHERE 0`: PostgreSQL-family engines (HighGo, Kingbase,+ // Vastbase, ...) and DuckDB require a boolean in WHERE and reject a bare integer+ // with "argument of WHERE must be type boolean, not type integer" (#9950).+ // `1=0` is a valid false predicate in every dialect, including the permissive+ // MySQL/SQLite-style engines that also accepted `0`.+ format!("CREATE TABLE {target} AS SELECT * FROM {source} WHERE 1=0;")};let mut comment_sql = Vec::new();@@ -2268,6 +2273,51 @@ mod tests {);}+ #[test]+ fn duplicate_table_structure_uses_boolean_false_predicate_for_pg_family_fallbacks() {+ // Regression for #9950: the generic fallback used `WHERE 0`. PostgreSQL-family+ // engines require a boolean there, so cloning a HighGo/Kingbase/Vastbase table+ // failed with "argument of WHERE must be type boolean, not type integer".+ for database_type in [+ DatabaseType::Highgo,+ DatabaseType::Kingbase,+ DatabaseType::Vastbase,+ DatabaseType::DuckDb,+ DatabaseType::Sqlite,+ ] {+ assert_eq!(+ build_duplicate_table_structure_sql(DuplicateTableStructureSqlOptions {+ database_type: Some(database_type),+ schema: Some("public".to_string()),+ source_name: "users".to_string(),+ target_name: "users_copy".to_string(),+ table_comment: None,+ column_comments: vec![],+ primary_key_columns: vec![],+ primary_key_constraint_name: None,+ identifier_quote: None,+ }),+ "CREATE TABLE \"public\".\"users_copy\" AS SELECT * FROM \"public\".\"users\" WHERE 1=0;",+ "{database_type:?}"+ );+ }+ // MySQL keeps the LIKE form, so the shared fallback must not have swallowed it.+ assert_eq!(+ build_duplicate_table_structure_sql(DuplicateTableStructureSqlOptions {+ database_type: Some(DatabaseType::Mysql),+ schema: None,+ source_name: "users".to_string(),+ target_name: "users_copy".to_string(),+ table_comment: None,+ column_comments: vec![],+ primary_key_columns: vec![],+ primary_key_constraint_name: None,+ identifier_quote: None,+ }),+ "CREATE TABLE `users_copy` LIKE `users`;"+ );+ }+#[test]fn builds_duplicate_table_structure_sql() {assert_eq!(