Vik Fearing <v...@postgresfriends.org> writes: > That is my preferred grammar, thank you. I have not looked at the C > code by this can be obtained with a syntax transformation. To wit:
> SELECT a, b, c > FROM tab > QUALIFY wf() OVER () = ? > can be rewritten as: > SELECT a, b, c > FROM ( > SELECT a, b, c, wf() OVER () = ? AS qc > FROM tab > ) AS q > WHERE qc That answers another question I was going to raise. Matheus's opening example was SELECT depname, empno, salary, RANK() OVER (PARTITION BY depname ORDER BY salary DESC) AS rnk FROM empsalary QUALIFY rnk = 1; which implies that the QUALIFY clause sees the SELECT output columns, and hence that it can't use any values not emitted by the SELECT list. Your transformation implies that it sees the same namespace as the SELECT list, which seems like a much better and less confusing definition to me. regards, tom lane