TimonKK / clickhouse

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

Access management queries fail because of obligatory FORMAT #142

Open ZiggerZZ opened 1 year ago

ZiggerZZ commented 1 year ago

await client.query("CREATE USER hello HOST ANY IDENTIFIED WITH sha256_password BY 'world').toPromise(); fails with ERROR [ExceptionsHandler] Syntax error: failed at position 77 ('FORMAT'): FORMAT JSON;

The library automatically ends a format (json/csv/tsv) and it makes sense for SELECT queries, however it fails for access management queries.

Any idea for a workaround?

ZiggerZZ commented 1 year ago

For those who need this as well: I ended up copying index.js to my project and replacing lines 523-525 by

        if (query.toUpperCase().startsWith('CREATE USER') ||
            query.toUpperCase().startsWith('GRANT SELECT') ||
            query.toUpperCase().startsWith('CREATE ROW POLICY')) {
        }
        else if ( ! R_FORMAT_PARSER.test(query)) {
          query += ` FORMAT ${ClickHouse.getFullFormatName(me.format)}`;
        }