CSV Import
To read data from a CSV file, use the read_csv function in the FROM clause of a query:
SELECT * FROM read_csv('input.csv');Alternatively, you can omit the read_csv function and let DuckDB infer it from the extension:
SELECT * FROM 'input.csv';To create a new table using the result from a query, use CREATE TABLE ... AS SELECT statement:
CREATE TABLE new_tbl AS SELECT * FROM read_csv('input.csv');We can use DuckDB’s optional FROM-first syntax to omit SELECT *:
CREATE TABLE new_tbl AS FROM read_csv('input.csv');To load data into an existing table from a query, use INSERT INTO from a SELECT statement:
INSERT INTO tbl SELECT * FROM read_csv('input.csv');Alternatively, the COPY statement can also be used to load data from a CSV file into an existing table:
COPY tbl FROM 'input.csv';For additional options, see the CSV import reference and the COPY statement documentation.