Percentile_disc() function does work with QRDS

Hello all!
First I should specify that the problem is happening on redash using PostgreSQL databases.
Now, I’m currently trying to set up alerts for specific queries in order for us to control the validity of our data.
In order to do so I made queries using the results from specific queries in order to be able to have one column to set up alerts for. In the query I’m using the aggregating function percentile_disc which allows you to select the percentile of your choice, and I’ve used it many times before without any issues.
But this time around I got a weird syntax error around the bra part of brackets: Error running query: **near "(": syntax error**. After checking too many times for my sanity the syntax and not finding any issues I am now asking you.
The query looks like that:
SELECT percentile_disc (0.25) within group(
ORDER BY diff) AS firstquart,
percentile_disc (0.75) within group(
ORDER BY diff) AS thirdquart
FROM query_581

I also tried this format:
WITH main AS
(SELECT diff
FROM query_581
WHERE currency = ‘INR’),
percentiles AS
(SELECT percentile_disc (0.25) within group(
ORDER BY diff) AS firstquart,
percentile_disc (0.75) within group(
ORDER BY diff) AS thirdquart
FROM main)
SELECT *
FROM percentiles

And I tried a few other formats, deleting as many brackets as I could, as well as other aggregating functions like avg() or sum(). I was able to pinpoint the problem to the percentile functions. And I believe it is linked to maybe a specific syntax associated with queries using existing query results?
In any case I couldn’t find any previous cases of this happening and no help.
Thank you in advance if you have an insight on or a solution for that problem!

QRDS doesn’t use Postgres. It uses an in-memory SQLite database to hold your query results. And SQLite doesn’t support percentile_disc. So it’s no surprise your query doesn’t work :wink:

Why do you use QRDS for this? Could you query directly against your Postgres database so you can use percentile_disc?

1 Like

I updated the title of this post to more accurately reflect the question.

Hi, sorry I should have specified I also tried that, but there are too many columns in my first query and adding the percentiles ended up not giving me any columns which I assume is due to an overwhelming amount of columns.
I also could maybe split the data of my first query into two queries, but I’d rather not do that if possible.

Edit: Oh ok I see. Guess I’ll have to split up my data. Thanks!

Thanks, sorry first time posting here, I’m not too aware of the habits and rules of posting here haha! :sweat_smile: