Unable to resolve column alias in PostgreSQL DISTINCT ON expression.
You can use column aliases within `DISTINCT ON` expressions. But it seems to be unable to resolve.


A more concise example:

These are all completely valid statements.
Here are the statements:
CREATE TABLE some_table (
PRIMARY KEY (id, n),
id text,
n numeric
);
INSERT INTO some_table
SELECT 'foo', random()
FROM generate_series(1, 10);
SELECT DISTINCT ON (id, expr)
id,
sum(n) OVER (PARTITION BY id) AS expr
FROM some_table;
SELECT DISTINCT ON (n) 1 AS n;
DataGrip 2021.2.3
Build #DB-212.5457.16, built on September 28, 2021
Licensed to Matter DK ApS / Aksel Tórgarð
Subscription is active until March 22, 2022.
Runtime version: 11.0.12+7-b1504.40 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Linux 5.14.12-arch1-1
GC: ParNew, ConcurrentMarkSweep
Memory: 1848M
Cores: 16
Current Desktop: Undefined
Please sign in to leave a comment.
Is it PostgreSQL?
Yep, PostgreSQL.