> For the complete documentation index, see [llms.txt](https://tricks.bodik.tech/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tricks.bodik.tech/databases/clickhouse/partition-clickhouse-table-based-on-unique-string-hash.md).

# Partition ClickHouse table based on unique string hash

I needed to create partitioning of the table based on unique string hash in range of \[1...400], to have max 400 of partitions

```
cast(((arrayReduce('sum', arrayMap(x -> reinterpretAsUInt32(x), arrayConcat(splitByString('', if(isNotNull(jobHash), jobHash, '')), []))) - 100) * (400 - 1) / (3500 - 100) + 1), 'UInt64')
```
