首页 分享 Importing Data

Importing Data

来源:花匠小妙招 时间:2025-08-15 21:29

Importing Data

The first step to using a database system is to insert data into that system. DuckDB can directly connect to many popular data sources and offers several data ingestion methods that allow you to easily and efficiently fill up the database. On this page, we provide an overview of these methods so you can select which one is best suited for your use case.

INSERT Statements

INSERT statements are the standard way of loading data into a database system. They are suitable for quick prototyping, but should be avoided for bulk loading as they have significant per-row overhead.

INSERT INTO people VALUES (1, 'Mark');

For a more detailed description, see the page on the INSERT statement.

File Loading: Relative Paths

Use the configuration option file_search_path to configure to which “root directories” relative paths are expanded on. If file_search_path is not set, the working directory is used as the basis for relative paths.

File Formats

CSV Loading

Data can be efficiently loaded from CSV files using several methods. The simplest is to use the CSV file's name:

SELECT * FROM 'test.csv';

Alternatively, use the read_csv function to pass along options:

SELECT * FROM read_csv('test.csv', header = false);

Or use the COPY statement:

COPY tbl FROM 'test.csv' (HEADER false);

It is also possible to read data directly from compressed CSV files (e.g., compressed with gzip):

SELECT * FROM 'test.csv.gz';

DuckDB can create a table from the loaded data using the CREATE TABLE ... AS SELECT statement:

CREATE TABLE test AS SELECT * FROM 'test.csv';

For more details, see the page on CSV loading.

Parquet Loading

Parquet files can be efficiently loaded and queried using their filename:

SELECT * FROM 'test.parquet';

Alternatively, use the read_parquet function:

SELECT * FROM read_parquet('test.parquet');

Or use the COPY statement:

COPY tbl FROM 'test.parquet';

For more details, see the page on Parquet loading.

JSON Loading

JSON files can be efficiently loaded and queried using their filename:

SELECT * FROM 'test.json';

Alternatively, use the read_json_auto function:

SELECT * FROM read_json_auto('test.json');

Or use the COPY statement:

COPY tbl FROM 'test.json';

For more details, see the page on JSON loading.

Returning the Filename

Since DuckDB v1.3.0, the CSV, JSON and Parquet readers support the filename virtual column:

COPY (FROM (VALUES (42), (43)) t(x)) TO 'test.parquet'; SELECT *, filename FROM 'test.parquet';

Appender

In several APIs (C, C++, Go, Java, and Rust), the Appender can be used as an alternative for bulk data loading. This class can be used to efficiently add rows to the database system without using SQL statements.

相关知识

Importing Data
SAP EPIC 银企直连 回单查询(建设银行)
Truffle global wholesale market price today
China Value Added Truffle market overview 2024
Css中路径data用法
Survey of structured data cleaning methods
佐田门窗 data=JSON
已知data = StringVar(),下列选项中可以将data设置为Pyth
使用 IBM Data Studio 管理数据库最佳实践1
Data和AI融合加速,TCHouse

网址: Importing Data https://www.huajiangbk.com/newsview2264746.html

所属分类:花卉
上一篇: 帽子花,定型花,饰品,手工花,小
下一篇: 花菲韩国饰品

推荐分享