clickhouse_driver.errors.ServerException: Code: 62.DB::Exception: Syntax error

5.6k Views Asked by At

I have an error in function.

self.client is click house driver --- from clickhouse_driver import Client

I called function with keys = "4"

def multi_get(self, keys: str) -> dict:
        if not self.initialized:
            self.make_table()
        keys_joined = "'" + "', '".join(keys) + "'"
        print(f"PPPP_1 {keys_joined}") # 4
        found = self.client.execute(
            f'SELECT max(arrivalTime), key, argMax(data, arrivalTime)'
            f' FROM {self.database}.cache'
            f' WHERE key in ({keys_joined})'
            f' and arrivalTime > now() - INTERVAL {self.expiration_interval}'
            ' GROUP BY key'
        )

And received error. How can I fix the error?

File "/home/alex/.local/lib/python3.6/site-packages/clickhouse_driver/client.py", line 118, in receive_packet raise packet.exception clickhouse_driver.errors.ServerException: Code: 62. DB::Exception: Syntax error: failed at position 137 ('GROUP'): GROUP BY key. Expected one of: HOUR, DD, SQL_TSI_QUARTER, S, SQL_TSI_YEAR, YEAR, LIKE,

1

There are 1 best solutions below

0
On

The error message is trying to tell you.

Here:

and arrivalTime > now() - INTERVAL {self.expiration_interval}

This generates invalid SQL. The INTERVAL requires a unit, like INTERVAL 1 HOUR, or else. The list of supported types can be found in the documentation:

SECOND
MINUTE
HOUR
DAY
WEEK
MONTH
QUARTER
YEAR

Maybe you want:

and arrivalTime > now() - INTERVAL {self.expiration_interval} HOUR