> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-fbfa8bee.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

>  `字典` 引擎以 ClickHouse 表的形式显示字典数据。

# 字典表引擎

`字典` 引擎以 ClickHouse 表的形式显示[字典](/zh/reference/statements/create/dictionary)数据。

<div id="example">
  ## 示例
</div>

例如，假设有一个名为 `products` 的字典，其配置如下：

```xml theme={null}
<dictionaries>
    <dictionary>
        <name>products</name>
        <source>
            <odbc>
                <table>products</table>
                <connection_string>DSN=some-db-server</connection_string>
            </odbc>
        </source>
        <lifetime>
            <min>300</min>
            <max>360</max>
        </lifetime>
        <layout>
            <flat/>
        </layout>
        <structure>
            <id>
                <name>product_id</name>
            </id>
            <attribute>
                <name>title</name>
                <type>String</type>
                <null_value></null_value>
            </attribute>
        </structure>
    </dictionary>
</dictionaries>
```

查询字典中的数据：

```sql theme={null}
SELECT
    name,
    type,
    key,
    attribute.names,
    attribute.types,
    bytes_allocated,
    element_count,
    source
FROM system.dictionaries
WHERE name = 'products'
```

```text theme={null}
┌─name─────┬─type─┬─key────┬─attribute.names─┬─attribute.types─┬─bytes_allocated─┬─element_count─┬─source──────────┐
│ products │ Flat │ UInt64 │ ['title']       │ ['String']      │        23065376 │        175032 │ ODBC: .products │
└──────────┴──────┴────────┴─────────────────┴─────────────────┴─────────────────┴───────────────┴─────────────────┘
```

你可以使用 [dictGet\*](/zh/reference/functions/regular-functions/ext-dict-functions) 函数，以这种格式获取字典中的数据。

当你需要获取原始数据或执行 `JOIN` 操作时，这种视图就不太有用了。此时，你可以使用 `字典` 引擎，它会以表的形式展示字典数据。

语法：

```sql theme={null}
CREATE TABLE %table_name% (%fields%) engine = Dictionary(%dictionary_name%)`
```

使用示例：

```sql theme={null}
CREATE TABLE products (product_id UInt64, title String) ENGINE = Dictionary(products);
```

好的

来看一下表中的内容。

```sql theme={null}
SELECT * FROM products LIMIT 1;
```

```text theme={null}
┌────product_id─┬─title───────────┐
│        152689 │ Some item       │
└───────────────┴─────────────────┘
```

**另请参阅**

* [字典函数](/zh/reference/functions/table-functions/dictionary)
