-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
EnhancementEnhance existing functionalityEnhance existing functionalitySQLIssues or changes relating to SQL executionIssues or changes relating to SQL execution
Description
To reproduce
On demo the following query
SELECT
timestamp, symbol,
first(price),
last(price),
CASE
when symbol = 'BTC-USD' THEN first(price)
else last(price)
END
FROM (trades where timestamp in today())
SAMPLE BY 1h
ALIGN TO CALENDAR WITH OFFSET '-00:15';gives Aggregate function cannot be passed as an argument. We should improve virtual model rewrite to extract expressions like the above CASE into an outer virtual model.
There is a similar limitation in WINDOW JOIN:
SELECT
t.symbol,
t.timestamp,
t.side,
t.price AS exec_price,
avg(p.bid_price) AS avg_bid,
avg(p.ask_price) AS avg_ask,
avg(p.ask_price - p.bid_price) AS avg_spread,
-- Slippage: did you pay more than ask (buy) or receive less than bid (sell)?
CASE
WHEN t.side = 'buy' THEN t.price - avg(p.ask_price)
ELSE avg(p.bid_price) - t.price
END AS slippage
FROM trades t
WINDOW JOIN prices p
ON (t.symbol = p.symbol)
RANGE BETWEEN 5 minutes PRECEDING AND 0 seconds PRECEDING
EXCLUDE PREVAILING
ORDER BY t.timestamp;gives WINDOW join cannot reference right table non-aggregate column: p.bid_price.
QuestDB version:
latest master
OS, in case of Docker specify Docker and the Host OS:
Linux
File System, in case of Docker specify Host File System:
ext4
Full Name:
Andrei Pechkurov
Affiliation:
QuestDB
Have you followed Linux, MacOs kernel configuration steps to increase Maximum open files and Maximum virtual memory areas limit?
- Yes, I have
Additional context
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
EnhancementEnhance existing functionalityEnhance existing functionalitySQLIssues or changes relating to SQL executionIssues or changes relating to SQL execution