2020-04-03 13:23:32 +00:00
---
2022-08-28 14:53:34 +00:00
slug: /en/engines/table-engines/special/dictionary
2022-04-09 13:29:05 +00:00
sidebar_position: 20
sidebar_label: Dictionary
2020-04-03 13:23:32 +00:00
---
2022-06-02 10:55:18 +00:00
# Dictionary Table Engine
2018-03-25 02:04:22 +00:00
2023-03-18 02:45:43 +00:00
The `Dictionary` engine displays the [dictionary ](../../../sql-reference/dictionaries/index.md ) data as a ClickHouse table.
2018-03-25 02:04:22 +00:00
2020-06-18 08:24:31 +00:00
## Example {#example}
2020-06-10 20:20:54 +00:00
2018-03-25 02:04:22 +00:00
As an example, consider a dictionary of `products` with the following configuration:
2020-03-20 10:10:48 +00:00
``` xml
2018-03-25 02:04:22 +00:00
< dictionaries >
2020-06-10 20:20:54 +00:00
< dictionary >
2018-03-25 02:04:22 +00:00
< 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 >
2020-06-10 20:20:54 +00:00
< / dictionary >
2018-03-25 02:04:22 +00:00
< / dictionaries >
```
Query the dictionary data:
2020-03-20 10:10:48 +00:00
``` sql
2018-05-08 11:50:38 +00:00
SELECT
name,
type,
key,
attribute.names,
attribute.types,
bytes_allocated,
element_count,
2018-03-25 02:04:22 +00:00
source
2018-05-08 11:50:38 +00:00
FROM system.dictionaries
2018-03-25 02:04:22 +00:00
WHERE name = 'products'
```
2018-04-23 06:20:21 +00:00
2020-03-20 10:10:48 +00:00
``` text
2018-03-25 02:04:22 +00:00
┌─name─────┬─type─┬─key────┬─attribute.names─┬─attribute.types─┬─bytes_allocated─┬─element_count─┬─source──────────┐
│ products │ Flat │ UInt64 │ ['title'] │ ['String'] │ 23065376 │ 175032 │ ODBC: .products │
└──────────┴──────┴────────┴─────────────────┴─────────────────┴─────────────────┴───────────────┴─────────────────┘
```
2020-04-30 18:19:18 +00:00
You can use the [dictGet\* ](../../../sql-reference/functions/ext-dict-functions.md#ext_dict_functions ) function to get the dictionary data in this format.
2018-03-25 02:04:22 +00:00
2020-03-20 10:10:48 +00:00
This view isn’ t helpful when you need to get raw data, or when performing a `JOIN` operation. For these cases, you can use the `Dictionary` engine, which displays the dictionary data in a table.
2018-03-25 02:04:22 +00:00
Syntax:
2020-03-20 10:10:48 +00:00
``` sql
2018-03-25 02:04:22 +00:00
CREATE TABLE %table_name% (%fields%) engine = Dictionary(%dictionary_name%)`
```
Usage example:
2020-03-20 10:10:48 +00:00
``` sql
2018-03-25 02:04:22 +00:00
create table products (product_id UInt64, title String) Engine = Dictionary(products);
```
2020-03-21 04:11:51 +00:00
Ok
2018-03-25 02:04:22 +00:00
2020-03-20 10:10:48 +00:00
Take a look at what’ s in the table.
``` sql
2018-03-25 02:04:22 +00:00
select * from products limit 1;
```
2018-05-08 11:50:38 +00:00
2020-03-20 10:10:48 +00:00
``` text
2018-03-25 02:04:22 +00:00
┌────product_id─┬─title───────────┐
2018-05-08 11:50:38 +00:00
│ 152689 │ Some item │
2018-03-25 02:04:22 +00:00
└───────────────┴─────────────────┘
```
2018-09-04 11:18:59 +00:00
2021-05-26 17:53:51 +00:00
**See Also**
2023-04-19 15:55:29 +00:00
- [Dictionary function ](../../../sql-reference/table-functions/dictionary.md#dictionary-function )