questdb
questdb copied to clipboard
Two WHERE on a query with no errors (and no effect)
Describe the bug
I found a case in which by mistake I added a second WHERE
to a query where I already had one. To my surprise, the parser didn't complain and the query was executed, just ignoring the second condition (which should have been an AND
instead)
WITH averaged AS (
SELECT timestamp, price, avg(price) OVER (PARTITION BY symbol order by timestamp RANGE BETWEEN '7' DAY PRECEDING AND CURRENT ROW) as moving_avg
FROM trades
WHERE symbol = 'BTC-USD' and timestamp > dateadd('d', -97, NOW())
)
SELECT * from averaged where timestamp > dateadd('d', -90, NOW()) where abs(moving_avg - price) > 2000
;
To reproduce
Go to questdb demo site and execute this
WITH averaged AS (
SELECT timestamp, price, avg(price) OVER (PARTITION BY symbol order by timestamp RANGE BETWEEN '7' DAY PRECEDING AND CURRENT ROW) as moving_avg
FROM trades
WHERE symbol = 'BTC-USD' and timestamp > dateadd('d', -97, NOW())
)
SELECT * from averaged where timestamp > dateadd('d', -90, NOW()) where abs(moving_avg - price) > 2000
;
Expected Behavior
Parser should throw an error. It should point out that an extra WHERE
is there. The user should replace it by an AND
, and the query should then execute.
Environment
- **QuestDB version**: 7.3.4
- **OS**: linux (demo site at demo.questdb.io)
- **Browser**:
Additional context
No response