feat(import): add SQL script import with dialect-aware parsing

This commit is contained in:
dadong
2026-08-27 17:17:41 +08:00
committed by GitHub
parent ab4e747bf9
commit dfd4d3b7ff
15 changed files with 809 additions and 12 deletions
+7 -2
View File
@@ -1,6 +1,6 @@
---
title: 表数据导入
description: 通过向导将 CSV、TSV、文本、JSON 或 Excel 数据导入现有表,或按文件批量创建新表。
description: 通过向导将 CSV、TSV、文本、JSON、Excel 或 SQL 数据导入现有表,或按文件批量创建新表。
---
表数据导入用于把文件数据写入数据库表。DBX 会先解析和预览文件,再让你确认解析选项、目标表、字段映射和执行方式,而不是选中文件后立即写入。
@@ -25,6 +25,11 @@ description: 通过向导将 CSV、TSV、文本、JSON 或 Excel 数据导入现
| 分隔文本 | `.txt` 等文本文件,可自定义分隔符 |
| JSON | 支持单个对象、对象数组或数组行;可以指定对象或数组结构 |
| Excel | 支持 `.xlsx`、`.xlsm` 和 `.xls`,可选择工作表 |
| SQL | 包含字面量 `INSERT INTO ... VALUES` 语句的 `.sql` 脚本,每个文件对应一张表 |
SQL 导入只接受字面量 `INSERT INTO ... VALUES` 行;表达式、`REPLACE`、`INSERT IGNORE`、`INSERT ... SELECT` 等无法无损改写的内容会被拒绝,以保留数据和语句语义。
SQL 导入通过非流式路径读取整个脚本,单个 `.sql` 文件不能超过 100 MB,超出上限会显式报错。`TO_DATE`、`TO_TIMESTAMP` 等日期函数的值会按第一个参数的文本导入,目标字段必须能解析该格式。
Desktop 直接读取所选本地文件;Docker/Web 会先把浏览器选择的文件上传到服务器临时目录,预览和导入结束后释放临时源文件。
@@ -67,7 +72,7 @@ Desktop 直接读取所选本地文件;Docker/Web 会先把浏览器选择的
### 文本编码
CSV、TSV 和分隔文本支持自动检测、UTF-8、GBK、UTF-16 LE 和 UTF-16 BE。自动检测不正确时,请手动选择编码后重新检查预览。
CSV、TSV、分隔文本和 SQL 脚本支持自动检测、UTF-8、GBK、UTF-16 LE 和 UTF-16 BE。自动检测不正确时,请手动选择编码后重新检查预览。
### 行范围
+7 -2
View File
@@ -1,6 +1,6 @@
---
title: Table Import
description: Use a guided workflow to import CSV, TSV, text, JSON, or Excel data into an existing table or create new tables in batches.
description: Use a guided workflow to import CSV, TSV, text, JSON, Excel, or SQL data into an existing table or create new tables in batches.
---
Table Import writes file data into database tables. DBX parses and previews the source first, then asks you to review parsing options, the target, column mappings, and execution settings before any rows are written.
@@ -25,6 +25,11 @@ Create-table mode accepts multiple files at once. Excel workbooks are expanded i
| Delimited text | Files such as `.txt` with a custom delimiter |
| JSON | A single object, object rows, or array rows; the shape can be selected explicitly |
| Excel | `.xlsx`, `.xlsm`, and `.xls`, with worksheet selection |
| SQL | `.sql` scripts containing literal `INSERT INTO ... VALUES` statements for one table |
SQL import accepts only literal `INSERT INTO ... VALUES` rows. Expressions, `REPLACE`, `INSERT IGNORE`, `INSERT ... SELECT`, and other constructs that cannot be rewritten losslessly are rejected so data and statement semantics are preserved.
SQL import reads the whole script through the non-streaming path, so each `.sql` file is limited to 100 MB; larger files are rejected with an explicit error. Values written with date functions such as `TO_DATE` and `TO_TIMESTAMP` are imported as the text of their first argument, and the target column must be able to parse that format.
Desktop reads selected local files directly. Docker/Web uploads browser-selected files to temporary server storage, then releases the prepared source after preview and import finish.
@@ -67,7 +72,7 @@ Desktop reads selected local files directly. Docker/Web uploads browser-selected
### Text Encoding
CSV, TSV, and delimited text support auto detection, UTF-8, GBK, UTF-16 LE, and UTF-16 BE. If detection is wrong, select an encoding manually and recheck the preview.
CSV, TSV, delimited text, and SQL scripts support auto detection, UTF-8, GBK, UTF-16 LE, and UTF-16 BE. If detection is wrong, select an encoding manually and recheck the preview.
### Row Range