2018-03-25 02:04:22 +00:00
# Dictionary
2018-12-12 17:28:00 +00:00
The `Dictionary` engine displays the [dictionary ](../../query_language/dicts/external_dicts.md ) data as a ClickHouse table.
2018-03-25 02:04:22 +00:00
As an example, consider a dictionary of `products` with the following configuration:
```xml
< 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 >
```
Query the dictionary data:
2019-09-23 15:31:46 +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
2019-09-23 15:31:46 +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 │
└──────────┴──────┴────────┴─────────────────┴─────────────────┴─────────────────┴───────────────┴─────────────────┘
```
2018-07-18 10:00:53 +00:00
You can use the [dictGet* ](../../query_language/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
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.
Syntax:
2019-09-23 15:31:46 +00:00
```sql
2018-03-25 02:04:22 +00:00
CREATE TABLE %table_name% (%fields%) engine = Dictionary(%dictionary_name%)`
```
Usage example:
2019-09-23 15:31:46 +00:00
```sql
2018-03-25 02:04:22 +00:00
create table products (product_id UInt64, title String) Engine = Dictionary(products);
```
```
2019-09-23 15:31:46 +00:00
Ok
2018-03-25 02:04:22 +00:00
```
Take a look at what's in the table.
2019-09-23 15:31:46 +00:00
```sql
2018-03-25 02:04:22 +00:00
select * from products limit 1;
```
2018-05-08 11:50:38 +00:00
2019-09-23 15:31:46 +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
2018-10-16 10:47:17 +00:00
[Original article ](https://clickhouse.yandex/docs/en/operations/table_engines/dictionary/ ) <!--hide-->