Re: BUG #15462: WITH ORDINALITY and CTEs don't work

From: hubert depesz lubaczewski <depesz(at)depesz(dot)com>
To: michael(dot)meyer(at)pace(dot)de, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #15462: WITH ORDINALITY and CTEs don't work
Date: 2018-10-26 11:34:26
Message-ID: 20181026113426.ddbpdbrh6eizxhxh@depesz.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Fri, Oct 26, 2018 at 10:55:57AM +0000, PG Bug reporting form wrote:
> CTEs don't play nicely together with 'WITH ORDINALITY':

Sure they do.

> This is working:
> SELECT * FROM generate_series(4,1,-1) WITH ORDINALITY;
> WITH a AS (SELECT * FROM generate_series(4,1,-1) )
> SELECT * FROM a;
>
> whereas this yields syntax error (42601)
>
> WITH a AS (SELECT * FROM generate_series(4,1,-1) )
> SELECT * FROM a WITH ORDINALITY;

This is because "with ORDINALITY" is for function call, not for any
table query.

So the correct syntax would be:

WITH a AS (SELECT * FROM generate_series(4,1,-1) WITH ORDINALITY) SELECT * FROM a;

depesz

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Jeff Janes 2018-10-26 14:08:00 Re: BUG #15459: no connection to the server
Previous Message PG Bug reporting form 2018-10-26 10:55:57 BUG #15462: WITH ORDINALITY and CTEs don't work