ClickHouse/docs/en/engines/table-engines/integrations/sqlite.md

59 lines
1.2 KiB
Markdown
Raw Normal View History

2021-08-15 14:11:37 +00:00
---
toc_priority: 7
toc_title: SQLite
---
# SQLite {#sqlite}
2021-08-15 13:53:49 +00:00
The engine allows to import and export data to SQLite and supports queries to SQLite tables directly from ClickHouse.
2021-08-15 13:53:49 +00:00
## Creating a Table {#creating-a-table}
2021-08-15 16:34:10 +00:00
2021-08-15 13:53:49 +00:00
``` sql
2021-08-18 13:40:09 +00:00
CREATE TABLE [IF NOT EXISTS] [db.]table_name
2021-08-15 16:34:10 +00:00
(
2021-08-18 13:40:09 +00:00
name1 [type1],
name2 [type2], ...
) ENGINE = SQLite('db_path', 'table')
2021-08-15 13:53:49 +00:00
```
**Engine Parameters**
- `db_path` — Path to SQLite file with a database.
- `table` — Name of a table in the SQLite database.
2021-08-15 13:53:49 +00:00
## Usage Example {#usage-example}
Shows a query creating the SQLite table:
2021-08-15 13:53:49 +00:00
2021-08-18 13:32:34 +00:00
```sql
SHOW CREATE TABLE sqlite_db.table2;
```
2021-08-15 13:53:49 +00:00
``` text
2021-08-18 13:32:34 +00:00
CREATE TABLE SQLite.table2
(
`col1` Nullable(Int32),
`col2` Nullable(String)
)
ENGINE = SQLite('sqlite.db','table2');
2021-08-15 13:53:49 +00:00
```
2021-08-18 13:32:34 +00:00
Returns the data from the table:
2021-08-15 13:53:49 +00:00
``` sql
2021-08-18 13:32:34 +00:00
SELECT * FROM sqlite_db.table2 ORDER BY col1;
2021-08-15 13:53:49 +00:00
```
2021-08-18 13:32:34 +00:00
```text
┌─col1─┬─col2──┐
│ 1 │ text1 │
│ 2 │ text2 │
│ 3 │ text3 │
└──────┴───────┘
2021-08-15 13:53:49 +00:00
```
**See Also**
- [SQLite](../../../engines/database-engines/sqlite.md) engine
2021-08-18 13:40:09 +00:00
- [sqlite](../../../sql-reference/table-functions/sqlite.md) table function