TimonKK / clickhouse

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

FORMAT PrettyCompact, Syntax error #103

Closed debian-testing closed 2 years ago

debian-testing commented 2 years ago

I am trying to use other formats, for example, FORMAT PrettyCompact to write to a file for reporting, however, the queries fail because FORMAT JSON; is being appended to the query after.

I read the docs, tried the format and raw options, tried removing the format options, setting it to null, etc., but no success.

There is code to process the FORMAT option, but I wasn't able to see any way to deactivate the postfixing of FORMAT JSON; without changing the source of this library.

Is there a way? Any ideas?

Test code (works directly in clickhouse-client)

...
    await clickhouse.query('DROP TABLE IF EXISTS t1').toPromise()
    await clickhouse.query('CREATE TABLE t1 (c1 Int8) ENGINE = MergeTree() ORDER BY (c1)').toPromise()
    await clickhouse.query('INSERT INTO t1 (c1) VALUES (1)').toPromise()
    const r = await clickhouse.query('SELECT * FROM t1 FORMAT PrettyCompact').toPromise()
...

Error: Syntax error: failed at position 25: PrettyCompact FORMAT JSON;

Version: clickhouse@2.4.2

UnamedRus commented 2 years ago

Because of https://github.com/TimonKK/clickhouse/issues/102

You can just append WITH 1 as a to your select query.

debian-testing commented 2 years ago

Thank you, works perfectly! (until #102 fixed...)

For reference: ClickHouse.opts.raw=true is required to properly receive the formatted results.