Data Import
Examples
The following examples use the [`flights.csv`](https://duckdb.org/data/flights.csv) file.  
Read a CSV file from disk, auto-infer options:  
```sql
SELECT * FROM 'flights.csv';
```  
Use the `read_csv` function with custom options:  
```sql
SELECT *
FROM read_csv('flights.csv',
delim = '|',
header = true,
columns = {
'FlightDate': 'DATE',
'UniqueCarrier': 'VARCHAR',
'OriginCityName': 'VARCHAR',
'DestCityName': 'VARCHAR'
});
```  
Read a CSV from stdin, auto-infer options:  
```bash
cat flights.csv | duckdb -c "SELECT * FROM read_csv('/dev/stdin')"
```  
Read a CSV file into a table:  
```sql
CREATE TABLE ontime (
FlightDate DATE,
UniqueCarrier VARCHAR,
OriginCityName VARCHAR,
DestCityName VARCHAR
);
COPY ontime FROM 'flights.csv';
```  
Alternatively, create a table without specifying the schema manually using a [`CREATE TABLE .. AS SELECT` statement](#docs:sql:statements:create_table::create-table--as-select-ctas):  
```sql
CREATE TABLE ontime AS
SELECT * FROM 'flights.csv';
```  
We can use the [`FROM`-first syntax](#docs:sql:query_syntax:from::from-first-syntax) to omit `SELECT *`.  
```sql
CREATE TABLE ontime AS
FROM 'flights.csv';
```  
Write the result of a query to a CSV file.  
```sql
COPY (SELECT * FROM ontime) TO 'flights.csv' WITH (HEADER, DELIMITER '|');
```  
If we serialize the entire table, we can simply refer to it with its name.  
```sql
COPY ontime TO 'flights.csv' WITH (HEADER, DELIMITER '|');
```