questdb / questdb/questdb

coalesce returns null on result from division by zero

Open
#3,308 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Question REST API
Dominant language
Java
Stars
17.3k
Forks
1.6k
Avg merge
5d 10h
Merged PRs (30d)
28

Description

TLDR Update: in aggregate functions (AVG / SUM / MAX / etc.), QDB internally handles -Infinity and Infinity values as nulls and do not calculate them into the final result. Column with 1000 Infinity values and two values of 1,3 will have the AVG of 2. which is wrong.

I see now behavior is changed and its actually returning null when dividing by zero. which can be treaded with a simple coalesce.

Describe the bug

coalesce should convert the nulls to something else.. in this case 0 but the result is all nulls.

I know some of my tickers may seem weird but this is a real scenario that actually happened to me on my server, I have just reproduced it on demo for your convenience.

To reproduce

try on demo questdb
SELECT *,A/G,coalesce(A/G,0) FROM (SELECT galon_price A,coalesce((galon_price1),0) G FROM (SELECT * FROM gas_prices b lt join (SELECT * FROM gas_prices a) on timestamp))

Expected Behavior

result should be 0

Environment
- **QuestDB version**: demo
- **OS**: ?
- **Browser**: chrome
Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the reported query on the QuestDB demo, focusing on division by zero, COALESCE, and the handling of Infinity values in aggregate results. Trace the SQL execution path for division and null substitution, then add or update a regression test covering COALESCE(A/G,0); done means the query returns 0 instead of null and the aggregate behavior is covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, sql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.