TimonKK / clickhouse

NodeJS client for ClickHouse
Apache License 2.0
220 stars 122 forks source link

CTE's don't respond with JSON format #106

Closed mike-luabase closed 2 years ago

mike-luabase commented 2 years ago

Queries with a CTE respond with the data as text without the normal JSON structure

let sql = `
with a1 as (select 1)
select * from a1
`
const d = await clickhouse.query(sql).toPromise();
console.log('clickhouse result: ', d)

result

clickhouse result:  1  2

Using clickhouse-client

lua-2 :) with a1 as (select 1 as a)
         select a, 2 as b from a1

WITH a1 AS
    (
        SELECT 1 AS a
    )
SELECT
    a,
    2 AS b
FROM a1

Query id: e5d31289-c52c-425a-90f1-d87786ac8298

┌─a─┬─b─┐
│ 1 │ 2 │
└───┴───┘

1 rows in set. Elapsed: 0.133 sec. 
mike-luabase commented 2 years ago

ClickHouse client version 21.12.3.32 (official build). Connected to ClickHouse server version 21.12.3 revision 54452.

mike-luabase commented 2 years ago

As mentioned here, adding with to this regex appears to fix the issue

if (query.match(/^(select|with|show|exists)/i)) {
TimonKK commented 2 years ago

The fix has been released