Skip to content

Commit 50b1fac

Browse files
alambspaydar
andauthored
Docs: Add query syntax to COPY docs (#7388)
* Docs: Add query syntax to `COPY` docs * prettier * Apply suggestions from code review Co-authored-by: Seth Paydar <29551413+spaydar@users.noreply.github.com> --------- Co-authored-by: Seth Paydar <29551413+spaydar@users.noreply.github.com>
1 parent c43d7be commit 50b1fac

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

docs/source/user-guide/sql/ddl.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
# DDL
2121

22+
DDL stands for "Data Definition Language" and relates to creating and
23+
modifying catalog objects such as Tables.
24+
2225
## CREATE DATABASE
2326

2427
Create catalog with specified name.

docs/source/user-guide/sql/dml.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,19 @@
1919

2020
# DML
2121

22+
DML stands for "Data Manipulation Language" and relates to inserting
23+
and modifying data in tables.
24+
2225
## COPY
2326

24-
Copy a table to file(s). Supported file formats are `parquet`, `csv`, and `json`.
27+
Copies the contents of a table or query to file(s). Supported file
28+
formats are `parquet`, `csv`, and `json` and can be inferred based on
29+
filename if writing to a single file.
2530

2631
The `PER_THREAD_OUTPUT` option treats `file_name` as a directory and writes a file per thread within it.
2732

2833
<pre>
29-
COPY <i><b>table_name</i></b> TO '<i><b>file_name</i></b>' [ ( <i><b>option</i></b> [, ... ] ) ]
34+
COPY { <i><b>table_name</i></b> | <i><b>query</i></b> } TO '<i><b>file_name</i></b>' [ ( <i><b>option</i></b> [, ... ] ) ]
3035

3136
where <i><b>option</i></b> can be one of:
3237
FORMAT <i><b>format_name</i></b>
@@ -35,14 +40,21 @@ where <i><b>option</i></b> can be one of:
3540
ROW_GROUP_LIMIT_BYTES <i><b>integer</i></b>
3641
</pre>
3742

43+
Copy the contents of `source_table` to `file_name.json` in JSON format:
44+
3845
```sql
3946
> COPY source_table TO 'file_name.json';
4047
+-------+
4148
| count |
4249
+-------+
4350
| 2 |
4451
+-------+
52+
```
53+
54+
Copy the contents of `source_table` to one or more Parquet formatted
55+
files in the `dir_name` directory:
4556

57+
```sql
4658
> COPY source_table TO 'dir_name' (FORMAT parquet, PER_THREAD_OUTPUT true);
4759
+-------+
4860
| count |
@@ -51,6 +63,19 @@ where <i><b>option</i></b> can be one of:
5163
+-------+
5264
```
5365

66+
Run the query `SELECT * from source ORDER BY time` and write the
67+
results (maintaining the order) to a parquet file named
68+
`output.parquet` with a maximum parquet row group size of 10MB:
69+
70+
```sql
71+
> COPY (SELECT * from source ORDER BY time) TO 'output.parquet' (ROW_GROUP_LIMIT_BYTES 10000000);
72+
+-------+
73+
| count |
74+
+-------+
75+
| 2 |
76+
+-------+
77+
```
78+
5479
## INSERT
5580

5681
Insert values into a table.

0 commit comments

Comments
 (0)