Skip to content

Commit

Permalink
Added query with 'with' support
Browse files Browse the repository at this point in the history
  • Loading branch information
kruglov committed Aug 13, 2024
1 parent 57c4676 commit b52b2c2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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());
}
}

0 comments on commit b52b2c2

Please sign in to comment.