Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ClickHouseStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ public function execute($params = null): Result
new \ArrayIterator(
mb_stripos($statement, 'select') === 0 ||
mb_stripos($statement, 'show') === 0 ||
mb_stripos($statement, 'describe') === 0
mb_stripos($statement, 'describe') === 0 ||
preg_match('/with(.*)\)\s*select/ms', mb_strtolower($statement)) == 1
? $this->client->select($statement)->rows()
: $this->client->write($statement)->rows()
)
Expand Down
16 changes: 16 additions & 0 deletions tests/SelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,20 @@ public function testTrimChar(): void

$this->assertEquals('t2', $result->fetchOne());
}

public function testWith(): void
{
$result = $this->connection->executeQuery("
WITH subselect as (
SELECT id
FROM test_select_table
WHERE payload = 'v4'
)
SELECT *
FROM test_select_table tbl
JOIN subselect sub ON sub.id = tbl.id
");

$this->assertEquals(2, $result->columnCount());
}
}