> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-3a82795f.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Allows to connect to SQLite databases and perform `INSERT` and `SELECT` queries to exchange data between ClickHouse and SQLite.

# SQLite

Allows to connect to [SQLite](https://www.sqlite.org/index.html) database and perform `INSERT` and `SELECT` queries to exchange data between ClickHouse and SQLite.

<h2 id="creating-a-database">
  Creating a database
</h2>

```sql theme={null}
    CREATE DATABASE sqlite_database
    ENGINE = SQLite('db_path')
```

**Engine Parameters**

* `db_path` — Path to a file with SQLite database.

<h2 id="data_types-support">
  Data types support
</h2>

The table below shows the default type mapping when ClickHouse automatically infers schema from SQLite:

| SQLite  | ClickHouse                              |
| ------- | --------------------------------------- |
| INTEGER | [Int32](/reference/data-types/int-uint) |
| REAL    | [Float32](/reference/data-types/float)  |
| TEXT    | [String](/reference/data-types/string)  |
| TEXT    | [UUID](/reference/data-types/uuid)      |
| BLOB    | [String](/reference/data-types/string)  |

When you explicitly define a table with specific ClickHouse types using the [SQLite table engine](/reference/engines/table-engines/integrations/sqlite), the following ClickHouse types can be parsed from SQLite TEXT columns:

* [Date](/reference/data-types/date), [Date32](/reference/data-types/date32)
* [DateTime](/reference/data-types/datetime), [DateTime64](/reference/data-types/datetime64)
* [UUID](/reference/data-types/uuid)
* [Enum8, Enum16](/reference/data-types/enum)
* [Decimal32, Decimal64, Decimal128, Decimal256](/reference/data-types/decimal)
* [FixedString](/reference/data-types/fixedstring)
* All integer types ([UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64](/reference/data-types/int-uint))
* [Float32, Float64](/reference/data-types/float)

SQLite has dynamic typing, and its type access functions perform automatic type coercion. For example, reading a TEXT column as an integer will return 0 if the text cannot be parsed as a number. This means that if a ClickHouse table is defined with a different type than the underlying SQLite column, values may be silently coerced rather than causing an error.

<h2 id="specifics-and-recommendations">
  Specifics and recommendations
</h2>

SQLite stores the entire database (definitions, tables, indices, and the data itself) as a single cross-platform file on a host machine. During writing SQLite locks the entire database file, therefore write operations are performed sequentially. Read operations can be multi-tasked.
SQLite does not require service management (such as startup scripts) or access control based on `GRANT` and passwords. Access control is handled by means of file-system permissions given to the database file itself.

<h2 id="usage-example">
  Usage example
</h2>

Database in ClickHouse, connected to the SQLite:

```sql theme={null}
CREATE DATABASE sqlite_db ENGINE = SQLite('sqlite.db');
SHOW TABLES FROM sqlite_db;
```

```text theme={null}
┌──name───┐
│ table1  │
│ table2  │
└─────────┘
```

Shows the tables:

```sql theme={null}
SELECT * FROM sqlite_db.table1;
```

```text theme={null}
┌─col1──┬─col2─┐
│ line1 │    1 │
│ line2 │    2 │
│ line3 │    3 │
└───────┴──────┘
```

Inserting data into SQLite table from ClickHouse table:

```sql theme={null}
CREATE TABLE clickhouse_table(`col1` String,`col2` Int16) ENGINE = MergeTree() ORDER BY col2;
INSERT INTO clickhouse_table VALUES ('text',10);
INSERT INTO sqlite_db.table1 SELECT * FROM clickhouse_table;
SELECT * FROM sqlite_db.table1;
```

```text theme={null}
┌─col1──┬─col2─┐
│ line1 │    1 │
│ line2 │    2 │
│ line3 │    3 │
│ text  │   10 │
└───────┴──────┘
```
