Skip to content

feat: allow GROUP BY ALL and DISTINCT for PostgreSQL - #2842

Merged
manticore-projects merged 2 commits into
JSQLParser:masterfrom
princejain756:pg-groupby-modifier
Oct 22, 2026
Merged

manticore-projects merged 2 commits into
JSQLParser:masterfrom
princejain756:pg-groupby-modifier

Conversation

@princejain756

Copy link
Copy Markdown
Contributor

Resolves #2785.

PostgreSQL accepts an optional ALL or DISTINCT modifier directly after GROUP BY:

SELECT 1 GROUP BY DISTINCT GROUPING SETS ((1), (1));
SELECT 1 GROUP BY ALL GROUPING SETS ((1), (2));
SELECT a FROM t GROUP BY DISTINCT a;

The DISTINCT form removes duplicate grouping sets before processing (PostgreSQL docs). JSQLParser rejected it at the DISTINCT token.

This adds a semantic-lookahead-gated ALL|DISTINCT slot in GroupByColumnReferences, active only under the POSTGRESQL dialect, plus all/distinct flags on GroupByElement so both toString and the deparser round-trip the modifier. Other dialects and existing GROUP BY forms are unchanged.

10,735 tests, 0 failures, 25 skipped.

@manticore-projects

Copy link
Copy Markdown
Contributor

Am I right to assume that this overlaps with #2830 but is broader?
If so, please resolve conflicts and I would merge.

@princejain756

Copy link
Copy Markdown
Contributor Author

Correct - #2830 handles GROUPING SETS under GROUP BY DISTINCT, while this adds ALL and DISTINCT before any grouping element, so it covers that case plus plain columns and rollups. Conflicts resolved, rebased on master.

@manticore-projects
manticore-projects merged commit ce3dce3 into JSQLParser:master Oct 22, 2026
10 checks passed
@manticore-projects

Copy link
Copy Markdown
Contributor

Thank you much!

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.

[BUG] JSQLParser : PostgreSQL : GROUP BY DISTINCT with GROUPING SETS fails to parse

2 participants