ClickHouse/docs/en/engines/database-engines/sqlite.md

81 lines
2.5 KiB
Markdown
Raw Normal View History

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**
- `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
| 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
## Specifics and Recommendations {#specifics-and-recommendations}
2021-08-15 13:53:49 +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}
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 │
└─────────┘
```
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 │
└───────┴──────┘
```