pg.ddx.io  pgdogdev/pgdog GitHub issues and pull requests  
help / color / mirror / Atom feed
From: murex971 (@murex971) <noreply+murex971@github.com>
To: pgdogdev/pgdog <noreply+pgdogdev-pgdog@github.com>
Subject: [pgdogdev/pgdog] issue #1927: Cross-shard GROUP BY on a SELECT alias returns wrong rows
Date: Sat, 31 Oct 2026 21:32:26 +0000
Message-ID: <gh-pgdogdev-pgdog-1927@github.com> (raw)


**Description**
When a query groups by a SELECT alias, PgDog doesn't recognize the alias as a GROUP BY column. When it merges results from the shards, it puts every row into one group.

Example:
`SELECT name AS n, count(*) FROM orders GROUP BY n;`
Postgres:
```
alice | 3
bob   | 2
carol | 2
dave  | 1
```
PgDog:
```
bob | 8
```

Grouping by the column name (GROUP BY name) or by position (GROUP BY 1) works correctly.

**Reference**
Vitess's end-to-end aggregation tests: [aggregation_test.go#L798](https://github.com/vitessio/vitess/blob/bf549e216779899ee12110b751132849f0920721/go/test/endtoend/vt...)
```
SELECT DATE(val1) AS date, SUM(val2) FROM aggr_test_dates GROUP BY date HAVING SUM(val2) > 100
```

view thread (4+ messages)  latest in thread

Message-ID: <gh-pgdogdev-pgdog-1927@github.com>
Permalink:  ../gh-pgdogdev-pgdog-1927@github.com/

 · 


This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox