ClickHouse/docs/en/engines/database-engines/sqlite.md
Anna fe8531c9f0
Update sqlite.md
Added example this "INSERT" query
2021-08-22 20:21:09 +03:00

2.4 KiB

toc_priority toc_title
32 SQLite

SQLite

Allows to connect to SQLite database.

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

SQLite ClickHouse
INTEGER Int32
REAL Float32
TEXT String
BLOB String

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 │
└───────┴──────┘