From 19b0695e05f1abab5f958692f047bbe0dceabd1e Mon Sep 17 00:00:00 2001 From: erikbaan <3224628+erikbaan@users.noreply.github.com> Date: Thu, 15 Apr 2021 11:32:59 +0200 Subject: [PATCH] ignore CTE in statement for select or write method --- src/ClickHouseStatement.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ClickHouseStatement.php b/src/ClickHouseStatement.php index 9587257..05e1390 100644 --- a/src/ClickHouseStatement.php +++ b/src/ClickHouseStatement.php @@ -326,9 +326,10 @@ public function getSql() : string protected function processViaSMI2(string $sql) : void { $sql = trim($sql); + $withoutCte = preg_replace('/WITH(.*)SELECT/ms', 'SELECT', $sql); $this->rows = - stripos($sql, 'select') === 0 || + stripos($withoutCte, 'select') === 0 || stripos($sql, 'show') === 0 || stripos($sql, 'describe') === 0 ? $this->smi2CHClient->select($sql)->rows() :