2021-08-15 14:11:37 +00:00
---
toc_priority: 32
toc_title: SQLite
---
# SQLite {#sqlite}
2021-08-15 13:53:49 +00:00
2021-08-22 17:28:47 +00:00
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.
2021-08-15 13:53:49 +00:00
## Creating a Database {#creating-a-database}
2021-08-15 16:34:10 +00:00
2021-08-15 13:53:49 +00:00
``` sql
2021-08-15 16:34:10 +00:00
CREATE DATABASE sqlite_database
ENGINE = SQLite('db_path')
2021-08-15 13:53:49 +00:00
```
**Engine Parameters**
2021-08-19 04:27:56 +00:00
- `db_path` — Path to a file with SQLite database.
2021-08-15 16:34:10 +00:00
## Data Types Support {#data_types-support}
2021-08-15 13:53:49 +00:00
2021-08-19 04:27:36 +00:00
| SQLite | ClickHouse |
2021-08-18 13:32:34 +00:00
|---------------|---------------------------------------------------------|
| INTEGER | [Int32 ](../../sql-reference/data-types/int-uint.md ) |
| REAL | [Float32 ](../../sql-reference/data-types/float.md ) |
| TEXT | [String ](../../sql-reference/data-types/string.md ) |
| BLOB | [String ](../../sql-reference/data-types/string.md ) |
2021-08-15 13:53:49 +00:00
2021-08-19 04:27:42 +00:00
## Specifics and Recommendations {#specifics-and-recommendations}
2021-08-15 13:53:49 +00:00
2021-08-19 04:28:12 +00:00
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 multitasked.
2021-08-15 16:34:10 +00:00
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.
2021-08-15 13:53:49 +00:00
## Usage Example {#usage-example}
2021-08-19 04:28:24 +00:00
Database in ClickHouse, connected to the SQLite:
2021-08-15 13:53:49 +00:00
``` sql
2021-08-18 13:32:34 +00:00
CREATE DATABASE sqlite_db ENGINE = SQLite('sqlite.db');
SHOW TABLES FROM sqlite_db;
2021-08-15 13:53:49 +00:00
```
``` text
2021-08-18 13:32:34 +00:00
┌──name───┐
│ table1 │
│ table2 │
└─────────┘
2021-08-22 17:21:09 +00:00
```
Shows the tables:
``` sql
SELECT * FROM sqlite_db.table1;
```
``` text
┌─col1──┬─col2─┐
│ line1 │ 1 │
│ line2 │ 2 │
│ line3 │ 3 │
└───────┴──────┘
```
Inserting data into SQLite table from ClickHouse table:
``` sql
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
┌─col1──┬─col2─┐
│ line1 │ 1 │
│ line2 │ 2 │
│ line3 │ 3 │
│ text │ 10 │
└───────┴──────┘
```