From 80f474aa3f477103367b8897cc17532a73aefc3d Mon Sep 17 00:00:00 2001 From: Marcus Nightingale Date: Wed, 15 Oct 2025 12:32:08 +0100 Subject: [PATCH] fix(clickhouse-driver): correct pagination offset handling in LIMIT clause Previously, the driver used `LIMIT , ` syntax, causing incorrect pagination behavior (page 2 repeating results from page 1, etc.). Updated the `limit()` function to use ClickHouse-compatible `LIMIT OFFSET ` syntax, ensuring correct row offsets across pages. --- plugins/drivers/clickhouse.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/drivers/clickhouse.php b/plugins/drivers/clickhouse.php index 7fa1d5fc8..827b92654 100644 --- a/plugins/drivers/clickhouse.php +++ b/plugins/drivers/clickhouse.php @@ -243,7 +243,14 @@ function get_databases($flush) { } function limit($query, $where, $limit, $offset = 0, $separator = " ") { - return " $query$where" . ($limit ? $separator . "LIMIT $limit" . ($offset ? ", $offset" : "") : ""); + if (!$limit) { + return " $query$where"; + } + $limitClause = "LIMIT " . (int) $limit; + if ($offset) { + $limitClause .= " OFFSET " . (int) $offset; + } + return " $query$where" . $separator . $limitClause; } function limit1($table, $query, $where, $separator = "\n") {