SELECT statements.
Creating a CSV virtual table
UseCREATE VIRTUAL TABLE ... USING csv(...) to expose a CSV source as a table:
Parameters
| Parameter | Values | Description |
|---|---|---|
filename | file path | Path to the CSV file on disk. Mutually exclusive with data. |
data | CSV string | Inline CSV content as a string literal. Mutually exclusive with filename. |
header | yes / no / true / false / on / off / 1 / 0 | Whether the first row contains column names. Default: no. |
columns | positive integer | Number of columns to expose. Rows with fewer columns return NULL for the missing fields; extra columns in the file are ignored. |
schema | SQL CREATE TABLE statement | Custom schema string. Overrides the automatically generated column definitions. |
You must specify exactly one of
filename or data. Providing both, or neither, is an error.Column naming
- When
header=yes, column names are taken from the first row of the CSV. - When
header=no, columns are namedc0,c1,c2, … by default. - Provide a
schemaargument to use any column names and types you choose.
Examples
Read a CSV file with a header row
Read inline CSV data
Provide a custom schema
Limit the number of columns
CSV format
The extension uses comma (,) as the field delimiter and double-quote (") as the quote character. Fields containing commas, newlines, or double-quotes must be enclosed in double-quotes. A literal double-quote inside a quoted field is represented by two consecutive double-quotes ("").
Limitations
- The CSV virtual table is read-only.
INSERT,UPDATE, andDELETEare not supported. - The extension reads the entire file on each query scan; there is no indexing.