2021-08-15 14:11:37 +00:00
|
|
|
---
|
2022-08-28 14:53:34 +00:00
|
|
|
slug: /en/engines/table-engines/integrations/sqlite
|
2022-04-09 13:29:05 +00:00
|
|
|
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
|
|
|
|
2021-08-19 04:28:41 +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**
|
|
|
|
|
2021-08-19 04:29:12 +00:00
|
|
|
- `db_path` — Path to SQLite file with a database.
|
2021-08-19 04:29:21 +00:00
|
|
|
- `table` — Name of a table in the SQLite database.
|
2021-08-15 13:53:49 +00:00
|
|
|
|
|
|
|
## Usage Example {#usage-example}
|
|
|
|
|
2021-08-19 04:29:26 +00:00
|
|
|
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**
|
|
|
|
|
2021-08-19 04:30:43 +00:00
|
|
|
- [SQLite](../../../engines/database-engines/sqlite.md) engine
|
2022-04-09 13:29:05 +00:00
|
|
|
- [sqlite](../../../sql-reference/table-functions/sqlite.md) table function
|