Re: FETCH FIRST clause WITH TIES option

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
Cc: Surafel Temesgen <surafel3000(at)gmail(dot)com>, Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: FETCH FIRST clause WITH TIES option
Date: 2020-04-08 03:25:57
Message-ID: 20200408032557.GA29002@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2020-Apr-08, Andrew Gierth wrote:

> >>>>> "Alvaro" == Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> writes:
>
> Alvaro> It turns out that the SQL standard is much more limited in what
> Alvaro> it will accept there. But our grammar (what we'll accept for
> Alvaro> the ancient LIMIT clause) is very lenient -- it'll take just
> Alvaro> any expression. I thought about reducing that to NumericOnly
> Alvaro> for FETCH FIRST .. WITH TIES, but then I have to pick: 1)
> Alvaro> gram.y fails to compile because of a reduce/reduce conflict, or
> Alvaro> 2) also restricting FETCH FIRST .. ONLY to NumericOnly. Neither
> Alvaro> of those seemed very palatable.
>
> FETCH FIRST ... ONLY was made _too_ restrictive initially, such that it
> didn't allow parameters (which are allowed by the spec); see 1da162e1f.

Hmm, oh, I see.

> (That change didn't present a problem for ruleutils, because FETCH FIRST
> ... ONLY is output as a LIMIT clause instead.)

Right, I noticed that and kept it unchanged.

> This needs to be fixed in ruleutils, IMO, not by changing what the
> grammar accepts.

Fair. I didn't change what the grammar accepts. I ended up only
throwing an error in parse analysis when a bare NULL const is seen.
I guess we could fix ruleutils to add parens when NULL is seen, but
I'm not sure it's necessary or useful. (LIMIT uses a null to represent
the LIMIT ALL case.)

--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2020-04-08 03:54:23 Re: [PATCH] Incremental sort (was: PoC: Partial sort)
Previous Message Amit Kapila 2020-04-08 03:06:34 Re: WAL usage calculation patch