---
title: "Semantic Versioning UDF in ClickHouse"
description: "A ClickHouse SQL UDF sorts app version strings by semantic version rather than lexicographically, so that 2.1.2 sorts before 2.1.10."
url: "https://swe.quest/articles/semantic-versioning-udf-in-clickhouse-c402b0d64cb4b011"
canonical: "https://clickhouse.com/blog/semantic-versioning-udf"
source: "ClickHouse"
published: "2024-10-09"
difficulty: "medium"
kind: "How-to"
reading_minutes: 6
tags: ["sql","analytics"]
---

# Semantic Versioning UDF in ClickHouse

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2024-10-09, 6 min read, How-to. Original: [https://clickhouse.com/blog/semantic-versioning-udf](https://clickhouse.com/blog/semantic-versioning-udf)

## Summary

A ClickHouse SQL UDF sorts app version strings by semantic version rather than lexicographically, so that 2.1.2 sorts before 2.1.10. It extracts the dotted numeric portion with a regex, splits it on periods, and maps each part to UInt32 with toUInt32OrZero, producing integer arrays that ClickHouse compares element-wise. Known limitations are that pre-release suffixes like -prod or -stg are dropped, so those versions tie, and that oddly shaped strings such as hash-based snapshots parse incorrectly. Embrace reports this is good enough in practice because customers tend to stick to one versioning scheme.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [SQL](https://swe.quest/tags/sql.md) (Languages)
- [Analytics & OLAP](https://swe.quest/tags/analytics.md) (Data & databases)

## Prerequisites

- SQL basics ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- regular expressions

## Keywords

ClickHouse, UDF, Semantic Versioning, Embrace

## Related posts

- [Type Constraints in 65 lines of SQL](https://swe.quest/articles/type-constraints-in-65-lines-of-sql-c09c12befbef6b57.md): Supabase · 2023-02-17 · Medium · 6 min read · PostgreSQL, SQL, Type systems
  A Postgres composite type plus a domain with check constraints can model Semantic Versioning so invalid versions are rejected on insert or cast.
- [ClickHouse Release 24.1](https://swe.quest/articles/clickhouse-release-24-1-4e8992d985c7e74d.md): ClickHouse · 2024-02-13 · Medium · 14 min read · Analytics & OLAP, SQL, Algorithms
  ClickHouse 24.1 ships 26 features, 22 performance optimisations and 47 bug fixes.
- [ClickHouse Over the Years with Benchmarks](https://swe.quest/articles/clickhouse-over-the-years-with-benchmarks-4ccceaaaa0dadc4e.md): ClickHouse · 2022-06-14 · Medium · 17 min read · Analytics & OLAP, Performance engineering, Databases
  Every ClickHouse release from 1.1.54378 (April 2018) onward was installed on one AWS m5.8xlarge and run through the Star Schema Benchmark, the Brown University benchmark and ClickHouse's own hits benchmark to see how performance changed over time.
- [Building a Paste Service With ClickHouse](https://swe.quest/articles/building-a-paste-service-with-clickhouse-1cd0d0d493c69976.md): ClickHouse · 2022-04-01 · Medium · 13 min read · Databases, Analytics & OLAP, Replication, System design, JavaScript
  pastila.nl is a minimal paste service whose browser JavaScript sends INSERT and SELECT queries directly to an internet-facing ClickHouse instance.
- [User-defined functions in ClickHouse Cloud](https://swe.quest/articles/user-defined-functions-in-clickhouse-cloud-33c541eadcfd2cd4.md): ClickHouse · 2022-12-08 · Medium · 6 min read · SQL, Analytics & OLAP, Version control
  ClickHouse SQL user-defined functions, now available in ClickHouse Cloud, can reconstruct a file's full commit history across renames in git-import data.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
