2020-03-20 10:10:48 +00:00
# Dictionary {#dictionary}
2018-03-25 02:04:22 +00:00
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:
2020-03-20 10:10:48 +00:00
``` xml
2018-03-25 02:04:22 +00:00
< 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:
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-03-20 10:10:48 +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
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
2020-01-30 10:34:55 +00:00
[Original article ](https://clickhouse.tech/docs/en/operations/table_engines/dictionary/ ) <!--hide-->