Skip to content

Redshift: Support APPROXIMATE PERCENTILE_DISC - #2480

Open
BenSatori wants to merge 8 commits into
apache:mainfrom
BenSatori:approximate-percentile-disc
Open

Redshift: Support APPROXIMATE PERCENTILE_DISC#2480
BenSatori wants to merge 8 commits into
apache:mainfrom
BenSatori:approximate-percentile-disc

Conversation

@BenSatori

Copy link
Copy Markdown
Contributor

Add Redshift support for APPROXIMATE PERCENTILE_DISC with WITHIN GROUP.

Previously, queries such as:

SELECT APPROXIMATE PERCENTILE_DISC(0.5)
WITHIN GROUP (ORDER BY totalprice)

failed to parse. Added a regression test based on the documented Redshift syntax.

@BenSatori
BenSatori force-pushed the approximate-percentile-disc branch from 68b491c to 88094e6 Compare September 3, 2026 10:49
Comment thread src/dialect/redshift.rs Outdated
// be a json path
impl Dialect for RedshiftSqlDialect {
fn parse_prefix(&self, parser: &mut Parser) -> Option<Result<Expr, ParserError>> {
if matches!(&parser.peek_token_ref().token, Token::Word(word) if word.value.eq_ignore_ascii_case("approximate"))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm this doesnt look like the correct place for this functionality, we already have function parsers in the parser and support other percentile_disc variants. so that I think we likely just need to adjust that logic to accept redshifts' syntax

Comment thread tests/sqlparser_redshift.rs Outdated
Comment on lines +564 to +571
r#"SELECT TOP 10 date.caldate,
COUNT(totalprice), SUM(totalprice),
APPROXIMATE PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY totalprice)
FROM listing
JOIN date ON listing.dateid = date.dateid
GROUP BY date.caldate
ORDER BY 3 DESC"#,
"SELECT TOP 10 date.caldate, COUNT(totalprice), SUM(totalprice), APPROXIMATE PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY totalprice) FROM listing JOIN date ON listing.dateid = date.dateid GROUP BY date.caldate ORDER BY 3 DESC",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets simplify this test input so that its clear what's being tested. also we should use verified_stmt

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing. Will do. My intuition was to use the example in Redshift's documentation, but I will change.

@BenSatori
BenSatori requested a review from iffyio September 7, 2026 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants