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

61 lines
1.2 KiB
Markdown
Raw Normal View History

2021-08-15 14:11:37 +00:00
---
2022-08-28 14:53:34 +00:00
slug: /en/engines/table-engines/integrations/sqlite
sidebar_position: 7
sidebar_label: SQLite
2021-08-15 14:11:37 +00:00
---
2022-06-02 10:55:18 +00:00
# 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
2022-06-02 10:55:18 +00:00
CREATE TABLE [IF NOT EXISTS] [db.]table_name
2021-08-15 16:34:10 +00:00
(
2022-06-02 10:55:18 +00:00
name1 [type1],
2021-08-18 13:40:09 +00:00
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
2022-06-02 10:55:18 +00:00
(
`col1` Nullable(Int32),
2021-08-18 13:32:34 +00:00
`col2` Nullable(String)
2022-06-02 10:55:18 +00:00
)
2021-08-18 13:32:34 +00:00
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
- [sqlite](../../../sql-reference/table-functions/sqlite.md) table function