Skip to main content

SQLite

Allows to connect to SQLite database and perform INSERT and SELECT queries to exchange data between ClickHouse and SQLite.

Creating a Database​

    CREATE DATABASE sqlite_database 
ENGINE = SQLite('db_path')

Engine Parameters

  • db_path β€” Path to a file with SQLite database.

Data Types Support​

SQLiteClickHouse
INTEGERInt32
REALFloat32
TEXTString
BLOBString

Specifics and Recommendations​

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. 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.

Usage Example​

Database in ClickHouse, connected to the SQLite:

CREATE DATABASE sqlite_db ENGINE = SQLite('sqlite.db');
SHOW TABLES FROM sqlite_db;
β”Œβ”€β”€name───┐
β”‚ table1 β”‚
β”‚ table2 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Shows the tables:

SELECT * FROM sqlite_db.table1;
β”Œβ”€col1──┬─col2─┐
β”‚ line1 β”‚ 1 β”‚
β”‚ line2 β”‚ 2 β”‚
β”‚ line3 β”‚ 3 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”˜

Inserting data into SQLite table from ClickHouse table:

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;
β”Œβ”€col1──┬─col2─┐
β”‚ line1 β”‚ 1 β”‚
β”‚ line2 β”‚ 2 β”‚
β”‚ line3 β”‚ 3 β”‚
β”‚ text β”‚ 10 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”˜