forked from gptscript-ai/structured-data-querier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport-context.txt
34 lines (25 loc) · 1.16 KB
/
export-context.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Documentation for exporting data from duckdb
This document describes how to export data from DuckDB to CSV, Excel, and JSON files, with example queries.
Takes data from a duckdb database table and writes a structured file with the contents.
## CSV Export (.csv extension)
To export the data from a table to a CSV file, use the COPY statement.
```
COPY {table} TO '{GPTSCRIPT_WORKSPACE_DIR}/{file}' (HEADER, DELIMITER ',');
```
## Excel Export (.xlsx extension)
To export the data from a table to an Excel file, install and load the spatial extension. This is only needed once per DuckDB connection.
```
INSTALL spatial;
LOAD spatial;
```
Then use the COPY statement. The file will contain one worksheet with the same name as the file, but without the .xlsx extension.
### Note
Dates and timestamps are currently not supported by the xlsx writer. Cast columns of those types to VARCHAR prior to creating the xlsx file.
```
COPY {table} TO '{GPTSCRIPT_WORKSPACE_DIR}/{file}' WITH (FORMAT GDAL, DRIVER 'xlsx');
```
## JSON Export (.json extension)
To export the data from a table to a JSON file, use the COPY statement.
```
COPY {table} TO '{GPTSCRIPT_WORKSPACE_DIR}/{file}';
```