From 6b214558f26c74307437c620d39b64a81a6080b7 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Mon, 30 Oct 2023 17:00:24 +0800 Subject: [PATCH 1/7] Add temp.md --- temp.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 temp.md diff --git a/temp.md b/temp.md new file mode 100644 index 000000000000..af27ff4986a7 --- /dev/null +++ b/temp.md @@ -0,0 +1 @@ +This is a test file. \ No newline at end of file From 966af9bd8ddda54be91553ab3c377a71d0e343c7 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Mon, 30 Oct 2023 17:00:29 +0800 Subject: [PATCH 2/7] Delete temp.md --- temp.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 temp.md diff --git a/temp.md b/temp.md deleted file mode 100644 index af27ff4986a7..000000000000 --- a/temp.md +++ /dev/null @@ -1 +0,0 @@ -This is a test file. \ No newline at end of file From 215d04d41b4ed38a9cc86a8493a89563ef0ca4a1 Mon Sep 17 00:00:00 2001 From: qiancai Date: Mon, 30 Oct 2023 17:34:39 +0800 Subject: [PATCH 3/7] add translation --- sql-statements/sql-statement-select.md | 74 ++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/sql-statements/sql-statement-select.md b/sql-statements/sql-statement-select.md index 3e16de54edf4..921a3d5c1d24 100644 --- a/sql-statements/sql-statement-select.md +++ b/sql-statements/sql-statement-select.md @@ -114,6 +114,8 @@ TableSampleOpt ::= ## 示例 +### SELECT + {{< copyable "sql" >}} ```sql @@ -174,6 +176,78 @@ mysql> SELECT AVG(s_quantity), COUNT(s_quantity) FROM stock; 1 row in set (0.52 sec) ``` +### SELECT ... INTO OUTFILE + +`SELECT ... INTO OUTFILE` 语句用于将查询结果写入到文件中。 + +> **注意:** +> +> 该语句不支持将查询结果写入任何[外部存储](https://docs.pingcap.com/tidb/stable/backup-and-restore-storages),如 Amazon S3 或 GCS。 + +在该语句中,你可以使用以下子句来指定输出文件的格式: + +- `FIELDS TERMINATED BY`:指定文件中字段的分隔符。例如,你可以将分隔符指定为 `','` 以输出逗号分隔值(CSV)或 `'\t'` 以输出制表符分隔值(TSV)。 +- `FIELDS ENCLOSED BY`:指定文件中包裹每个字段的字符。 +- `LINES TERMINATED BY`:如果你希望以某个特殊的字符为结尾来切分行数据,可以使用该子句指定文件中行的终止符。 + +假设有一个名为 `t` 的表,包含以下三列: + +```sql +mysql> CREATE TABLE t (a INT, b VARCHAR(10), c DECIMAL(10,2)); +Query OK, 0 rows affected (0.02 sec) + +mysql> INSERT INTO t VALUES (1, 'a', 1.1), (2, 'b', 2.2), (3, 'c', 3.3); +Query OK, 3 rows affected (0.01 sec) +``` + +以下示例展示了如何使用 `SELECT ... INTO OUTFILE` 语句将查询结果写入到文件中。 + +**示例 1:** + +```sql +mysql> SELECT * FROM t INTO OUTFILE '/tmp/tmp_file1'; +Query OK, 3 rows affected (0.00 sec) +``` + +在此示例中,你可以在 `/tmp/tmp_file1` 中看到以下查询结果: + +``` +1 a 1.10 +2 b 2.20 +3 c 3.30 +``` + +**示例 2:** + +```sql +mysql> SELECT * FROM t INTO OUTFILE '/tmp/tmp_file2' FIELDS TERMINATED BY ',' ENCLOSED BY '"'; +Query OK, 3 rows affected (0.00 sec) +``` + +在此示例中,你可以在 `/tmp/tmp_file2`中看到以下查询结果: + +``` +"1","a","1.10" +"2","b","2.20" +"3","c","3.30" +``` + +**示例 3:** + +```sql +mysql> SELECT * FROM t INTO OUTFILE '/tmp/tmp_file3' + -> FIELDS TERMINATED BY ',' ENCLOSED BY '\'' LINES TERMINATED BY '<<<\n'; +Query OK, 3 rows affected (0.00 sec) +``` + +在此示例中,你可以在 `/tmp/tmp_file3`中看到以下查询结果: + +``` +'1','a','1.10'<<< +'2','b','2.20'<<< +'3','c','3.30'<<< +``` + ## MySQL 兼容性 - 不支持 `SELECT ... INTO @variable` 语法。 From 7fbbb4eb84bdfefd322f033339aff355dfe81417 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Mon, 30 Oct 2023 17:39:02 +0800 Subject: [PATCH 4/7] Update sql-statements/sql-statement-select.md --- sql-statements/sql-statement-select.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-statements/sql-statement-select.md b/sql-statements/sql-statement-select.md index 921a3d5c1d24..1e11c54e6b60 100644 --- a/sql-statements/sql-statement-select.md +++ b/sql-statements/sql-statement-select.md @@ -182,7 +182,7 @@ mysql> SELECT AVG(s_quantity), COUNT(s_quantity) FROM stock; > **注意:** > -> 该语句不支持将查询结果写入任何[外部存储](https://docs.pingcap.com/tidb/stable/backup-and-restore-storages),如 Amazon S3 或 GCS。 +> 该语句不支持将查询结果写入任何[外部存储](/br/backup-and-restore-storages.md),如 Amazon S3 或 GCS。 在该语句中,你可以使用以下子句来指定输出文件的格式: From 2596db529db02213fc974855a99a3e1f8da90dea Mon Sep 17 00:00:00 2001 From: qiancai Date: Mon, 30 Oct 2023 17:40:39 +0800 Subject: [PATCH 5/7] Update sql-statement-select.md --- sql-statements/sql-statement-select.md | 1 + 1 file changed, 1 insertion(+) diff --git a/sql-statements/sql-statement-select.md b/sql-statements/sql-statement-select.md index 1e11c54e6b60..4066f39bd7d2 100644 --- a/sql-statements/sql-statement-select.md +++ b/sql-statements/sql-statement-select.md @@ -251,6 +251,7 @@ Query OK, 3 rows affected (0.00 sec) ## MySQL 兼容性 - 不支持 `SELECT ... INTO @variable` 语法。 +- 不支持 `SELECT ... INTO DUMPFILE` 语法。 - 不支持 MySQL 5.7 中支持的 `SELECT .. GROUP BY expr` 语法,而是匹配 MySQL 8.0 的行为,不按照默认的顺序进行排序。 - `SELECT ... TABLESAMPLE ...` 是 TiDB 的扩展语法,MySQL 不支持该语法。 From ec058660033bbc0e131a3bdbf9518c2c5c1f45d5 Mon Sep 17 00:00:00 2001 From: qiancai Date: Mon, 30 Oct 2023 17:42:55 +0800 Subject: [PATCH 6/7] Update sql-statement-select.md --- sql-statements/sql-statement-select.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql-statements/sql-statement-select.md b/sql-statements/sql-statement-select.md index 4066f39bd7d2..c3a3df745cd4 100644 --- a/sql-statements/sql-statement-select.md +++ b/sql-statements/sql-statement-select.md @@ -224,7 +224,7 @@ mysql> SELECT * FROM t INTO OUTFILE '/tmp/tmp_file2' FIELDS TERMINATED BY ',' EN Query OK, 3 rows affected (0.00 sec) ``` -在此示例中,你可以在 `/tmp/tmp_file2`中看到以下查询结果: +在此示例中,你可以在 `/tmp/tmp_file2` 中看到以下查询结果: ``` "1","a","1.10" @@ -240,7 +240,7 @@ mysql> SELECT * FROM t INTO OUTFILE '/tmp/tmp_file3' Query OK, 3 rows affected (0.00 sec) ``` -在此示例中,你可以在 `/tmp/tmp_file3`中看到以下查询结果: +在此示例中,你可以在 `/tmp/tmp_file3` 中看到以下查询结果: ``` '1','a','1.10'<<< From 6358bb5fe1cecc3f608ac4e0a5dd6f07aedef8d1 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Tue, 28 Nov 2023 18:05:41 +0800 Subject: [PATCH 7/7] Update sql-statements/sql-statement-select.md --- sql-statements/sql-statement-select.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-statements/sql-statement-select.md b/sql-statements/sql-statement-select.md index c3a3df745cd4..431c50320720 100644 --- a/sql-statements/sql-statement-select.md +++ b/sql-statements/sql-statement-select.md @@ -253,7 +253,7 @@ Query OK, 3 rows affected (0.00 sec) - 不支持 `SELECT ... INTO @variable` 语法。 - 不支持 `SELECT ... INTO DUMPFILE` 语法。 - 不支持 MySQL 5.7 中支持的 `SELECT .. GROUP BY expr` 语法,而是匹配 MySQL 8.0 的行为,不按照默认的顺序进行排序。 -- `SELECT ... TABLESAMPLE ...` 是 TiDB 的扩展语法,MySQL 不支持该语法。 +- `SELECT ... TABLESAMPLE ...` 是 TiDB 的扩展语法,用于兼容其他数据库以及 [ISO/IEC 9075-2](https://standards.iso.org/iso-iec/9075/-2/ed-6/en/) 标准,但 MySQL 不支持该语法。 ## 另请参阅