2022-02-19 07:14:22 +00:00
|
|
|
|
---
|
|
|
|
|
toc_priority: 7
|
|
|
|
|
toc_title: SQLite
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
# SQLite {#sqlite}
|
|
|
|
|
|
2022-02-19 07:20:34 +00:00
|
|
|
|
该引擎允许导入和导出数据到SQLite,并支持查询SQLite表直接从ClickHouse。
|
2022-02-19 07:14:22 +00:00
|
|
|
|
|
2022-02-19 07:20:34 +00:00
|
|
|
|
## 创建数据表 {#creating-a-table}
|
2022-02-19 07:14:22 +00:00
|
|
|
|
|
|
|
|
|
``` sql
|
|
|
|
|
CREATE TABLE [IF NOT EXISTS] [db.]table_name
|
|
|
|
|
(
|
|
|
|
|
name1 [type1],
|
|
|
|
|
name2 [type2], ...
|
|
|
|
|
) ENGINE = SQLite('db_path', 'table')
|
|
|
|
|
```
|
|
|
|
|
|
2022-02-19 07:20:34 +00:00
|
|
|
|
**引擎参数**
|
2022-02-19 07:14:22 +00:00
|
|
|
|
|
2022-02-19 07:20:34 +00:00
|
|
|
|
- `db_path` — SQLite数据库文件的具体路径地址。
|
|
|
|
|
- `table` — SQLite数据库中的表名。
|
2022-02-19 07:14:22 +00:00
|
|
|
|
|
2022-02-19 07:20:34 +00:00
|
|
|
|
## 使用示例 {#usage-example}
|
2022-02-19 07:14:22 +00:00
|
|
|
|
|
2022-02-19 07:20:34 +00:00
|
|
|
|
显示创建表的查询语句:
|
2022-02-19 07:14:22 +00:00
|
|
|
|
|
|
|
|
|
```sql
|
|
|
|
|
SHOW CREATE TABLE sqlite_db.table2;
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
``` text
|
|
|
|
|
CREATE TABLE SQLite.table2
|
|
|
|
|
(
|
|
|
|
|
`col1` Nullable(Int32),
|
|
|
|
|
`col2` Nullable(String)
|
|
|
|
|
)
|
|
|
|
|
ENGINE = SQLite('sqlite.db','table2');
|
|
|
|
|
```
|
|
|
|
|
|
2022-02-19 07:20:34 +00:00
|
|
|
|
从数据表查询数据:
|
2022-02-19 07:14:22 +00:00
|
|
|
|
|
|
|
|
|
``` sql
|
|
|
|
|
SELECT * FROM sqlite_db.table2 ORDER BY col1;
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```text
|
|
|
|
|
┌─col1─┬─col2──┐
|
|
|
|
|
│ 1 │ text1 │
|
|
|
|
|
│ 2 │ text2 │
|
|
|
|
|
│ 3 │ text3 │
|
|
|
|
|
└──────┴───────┘
|
|
|
|
|
```
|
|
|
|
|
|
2022-02-19 07:20:34 +00:00
|
|
|
|
**详见**
|
2022-02-19 07:14:22 +00:00
|
|
|
|
|
2022-02-19 07:20:34 +00:00
|
|
|
|
- [SQLite](../../../engines/database-engines/sqlite.md) 引擎
|
|
|
|
|
- [sqlite](../../../sql-reference/table-functions/sqlite.md) 表方法函数
|