Re: Parameters don't work in FETCH NEXT clause?

From: Shay Rojansky <roji(at)roji(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Parameters don't work in FETCH NEXT clause?
Date: 2016-05-17 16:15:11
Message-ID: CADT4RqBsC1YsX2ByQCDAfRNYFDU=+uBvxxL1X9=+B6=M6es8Rw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Apologies, as usual I didn't read the docs carefully enough.

On Tue, May 17, 2016 at 7:13 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Shay Rojansky <roji(at)roji(dot)org> writes:
> > A user of mine just raised a strange issue... While it is possible to
> use a
> > parameter in a LIMIT clause, PostgreSQL does not seem to allow using one
> in
> > a FETCH NEXT clause. In other words, while the following works:
> > SELECT 1 LIMIT $1;
> > The following generates a syntax error:
> > SELECT 1 FETCH NEXT $1 ROWS ONLY;
> > Since LIMIT and FETCH NEXT are supposed to be equivalent this behavior is
> > odd.
>
> Per the SELECT reference page:
>
> SQL:2008 introduced a different syntax to achieve the same result,
> which PostgreSQL also supports. It is:
>
> OFFSET start { ROW | ROWS }
> FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } ONLY
>
> In this syntax, to write anything except a simple integer constant for
> start or count, you must write parentheses around it.
>
> The comments about this in gram.y are informative:
>
> * Allowing full expressions without parentheses causes various parsing
> * problems with the trailing ROW/ROWS key words. SQL only calls for
> * constants, so we allow the rest only with parentheses. If omitted,
> * default to 1.
>
> regards, tom lane
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jaime Casanova 2016-05-17 16:43:50 Re: 10.0
Previous Message Tom Lane 2016-05-17 16:13:09 Re: Parameters don't work in FETCH NEXT clause?