Repository navigation
Description
Hello.
Yesterday I wrote about unexpected behaviour: #43747
Some preview again:
I've some table. Each date contains data snapshots for 15 days ago and 50 days ahead. If I'll go to my table and run SELECT WHERE date = '2022-01-27' I will get rows with block_date from 2022-01-13 to 2022-03-18. I need to build reports per month, so at date = '2022-01-27' I need to see rows with block_date from 2022-01-01 to 2022-01-31. I can find this missing information if I go back a day. At date = '2022-01-26' I will find information for block_date = 2022-01-12 and so on.
For example I've these rows:
|date | block_date | total_plan_volume_grp20 |
| -----------| ------------ | -------------------------|
| 2022-01-27 | 2022-01-14 | 10 |
| 2022-01-27 | 2022-01-13 | 20 |
| 2022-01-26 | 2022-01-14 | 10 |
| 2022-01-26 | 2022-01-13 | 20 |
| 2022-01-26 | 2022-01-12 | 30 |
| 2022-01-25 | 2022-01-14 | 10 |
| 2022-01-25 | 2022-01-13 | 20 |
| 2022-01-25 | 2022-01-12 | 30 |
| 2022-01-25 | 2022-01-11 | 40 |
I expect to get this:
|date |block_date |total_plan_volume_grp20 |
| -------- | ------------ | ------------------------- |
| 2022-01-27 | 2022-01-14 | 10 |
| 2022-01-27 | 2022-01-13 | 20 |
| 2022-01-27 | 2022-01-12 | 30 |
| 2022-01-27 | 2022-01-11 | 40 |
| 2022-01-26 | 2022-01-14 | 10 |
| 2022-01-26 | 2022-01-13 | 20 |
| 2022-01-26 | 2022-01-12 | 30 |
| 2022-01-26 | 2022-01-11 | 40 |
| 2022-01-25 | 2022-01-14 | 10 |
| 2022-01-25 | 2022-01-13 | 20 |
| 2022-01-25 | 2022-01-12 | 30 |
| 2022-01-25 | 2022-01-11 | 40 |
Early we used PostgreSQL and query below works fine with Postge. I tried to modify query a bit and run it in ClickHouse.
I decided to change my first query to replace WHERE EXISTS. Now I run with JOIN, but it still doesn't work and I'm stuck.
Query:
SELECT
DISTINCT
t1.date, t2.block_date, t2.total_plan_volume_grp20
FROM connectors.historical_data_storage t1
JOIN connectors.historical_data_storage t2 ON t2.date BETWEEN t1.date-15 AND t1.date
It throws an error:
Unsupported JOIN ON conditions. Unexpected 't2.date >= (date - 15)': While processing t2.date >= (date - 15). (INVALID_JOIN_ON_EXPRESSION) (version 22.10.2.11 (official build))
Activity
den-crane commentedon Nov 29, 2022
CH supports only equi join https://www.w3resource.com/sql/joins/perform-an-equi-join.php
see workarounds: https://fiddle.clickhouse.com/2a250d47-035d-401b-bf39-486e1747a780