Re: Proposal: QUALIFY clause - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Proposal: QUALIFY clause
Date
Msg-id 661034.1753138575@sss.pgh.pa.us
Whole thread Raw
In response to Re: Proposal: QUALIFY clause  (Vik Fearing <vik@postgresfriends.org>)
List pgsql-hackers
Vik Fearing <vik@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



pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Support for 8-byte TOAST values (aka the TOAST infinite loop problem)
Next
From: Michael Paquier
Date:
Subject: Re: Verify predefined LWLocks tranches have entries in wait_event_names.txt