Skip to content

parser: reject DISTINCT ON instead of fabricating an ON() call#54

Merged
chiradip merged 1 commit into
mainfrom
reject-distinct-on
Jul 27, 2026
Merged

parser: reject DISTINCT ON instead of fabricating an ON() call#54
chiradip merged 1 commit into
mainfrom
reject-distinct-on

Conversation

@chiradip

@chiradip chiradip commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Second-pass audit finding F3 (dialect gap, silently-wrong-AST). SELECT DISTINCT ON (a) a, b FROM t was silently mis-parsed: after consuming DISTINCT, the select-list parser read ON (a) as a function call ON(a) occupying the first output slot, then took the intended first column a as that call's alias — dropping a projected column and turning the query into SELECT DISTINCT ON(a) AS a, b.

DISTINCT ON (a PostgreSQL extension) is not supported. Reject it cleanly right after DISTINCT (error, no AST) rather than producing the wrong tree. Plain DISTINCT (no ON) is unaffected.

Full DISTINCT ON support (distinct-on expression list + its analyzer/binder legs) is a separate feature, out of scope — this removes the silent mis-parse.

Tests (test_parser_negative)

DISTINCT ON (...) is rejected; plain DISTINCT a, b still parses. Full suite 37/37.

`SELECT DISTINCT ON (a) a, b FROM t` was silently mis-parsed: after
consuming DISTINCT the select-list parser read `ON (a)` as a function call
`ON(a)` occupying the first output slot, then took the intended first
column `a` as that call's alias -- dropping a projected column and turning
the query into `SELECT DISTINCT ON(a) AS a, b`.

DISTINCT ON (a PostgreSQL extension) is not supported. Reject it cleanly
right after DISTINCT (error, no AST) rather than producing the wrong tree.
Plain DISTINCT (no ON) is unaffected.

Tests (test_parser_negative): `DISTINCT ON (...)` is rejected; plain
`DISTINCT a, b` still parses. Full suite 37/37.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FyKDAbMWGwiZq4iJx3imsg
@chiradip
chiradip merged commit 532fc39 into main Jul 27, 2026
8 checks passed
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.

1 participant