TimonKK / clickhouse

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

How to parameterize query #97

Closed Mauzzz0 closed 2 years ago

Mauzzz0 commented 3 years ago

Hi. I see that query method of ClickHouse class have reqParams?. How to use it? I tried like mysql: const r = await clickhouse.query('select * from table where id=? and name=?', [1, 'jane']).toPromise() And in result i expect to list of all rows from table 'table', where id is equal to 1 and name is 'jane' But i get error of parameter tag:

e.displayText() = DB::Exception: Syntax error: failed at position 84 ('?') (line 3, col 18): ? and name=? FORMAT JSON;\n. Expected one of: EXTRACT, TIMESTAMPADD, TIMESTAMPDIFF, TIMESTAMP_DIFF, TRIM............

I know that it was happened because i used incorrect symbol for parameter. Which symbol i should use for set parameters in query?

TimonKK commented 2 years ago

Hi. The query cannot be parameterized in this way. You should do it yourself before query method

TimonKK commented 2 years ago

Hi, now you can use like this https://github.com/TimonKK/clickhouse/blob/master/test/test.js#L279

Mauzzz0 commented 2 years ago

Sounds good