Skip to content

Commit b52b2c2

Browse files
author
kruglov
committed
Added query with 'with' support
1 parent 57c4676 commit b52b2c2

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/ClickHouseStatement.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ public function execute($params = null): Result
124124
new \ArrayIterator(
125125
mb_stripos($statement, 'select') === 0 ||
126126
mb_stripos($statement, 'show') === 0 ||
127-
mb_stripos($statement, 'describe') === 0
127+
mb_stripos($statement, 'describe') === 0 ||
128+
preg_match('/with(.*)\)\s*select/ms', mb_strtolower($statement)) == 1
128129
? $this->client->select($statement)->rows()
129130
: $this->client->write($statement)->rows()
130131
)

tests/SelectTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,20 @@ public function testTrimChar(): void
243243

244244
$this->assertEquals('t2', $result->fetchOne());
245245
}
246+
247+
public function testWith(): void
248+
{
249+
$result = $this->connection->executeQuery("
250+
WITH subselect as (
251+
SELECT id
252+
FROM test_select_table
253+
WHERE payload = 'v4'
254+
)
255+
SELECT *
256+
FROM test_select_table tbl
257+
JOIN subselect sub ON sub.id = tbl.id
258+
");
259+
260+
$this->assertEquals(2, $result->columnCount());
261+
}
246262
}

0 commit comments

Comments
 (0)