Обсуждение: ERROR: ORDER/GROUP BY expression not found in targetlist

Поиск
Список
Период
Сортировка

ERROR: ORDER/GROUP BY expression not found in targetlist

От
Rushabh Lathia
Дата:
Hi,

Consider the below testcase:

CREATE TABLE tab(
  c1 INT NOT NULL,
  c2 INT NOT NULL
);
INSERT INTO tab VALUES (1, 2);
INSERT INTO tab VALUES (2, 1);
INSERT INTO tab VALUES (1, 2);


case 1:

SELECT c.c1, c.c2 from tab C WHERE c.c2 = ANY (
    SELECT 1 FROM tab A WHERE a.c2 IN (
      SELECT 1 FROM tab B WHERE a.c1 = c.c1
      GROUP BY rollup(a.c1)
    )
    GROUP BY cube(c.c2)
  )
  GROUP BY grouping sets(c.c1, c.c2)
  ORDER BY 1, 2 DESC;
ERROR:  ORDER/GROUP BY expression not found in targetlist

case 2:

create sequence s;
SELECT setval('s', max(100)) from tab;
ERROR:  ORDER/GROUP BY expression not found in targetlist

Looking further I found that error started coming with below commit:

commit aeb9ae6457865c8949641d71a9523374d843a418
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date:   Thu May 26 14:52:24 2016 -0400

    Disable physical tlist if any Var would need multiple sortgroupref labels.

If we revert the above commit, then the give test are running
as expected.


Regards,
Rushabh Lathia

Re: ERROR: ORDER/GROUP BY expression not found in targetlist

От
Amit Langote
Дата:
On Tue, Jun 28, 2016 at 2:52 PM, Rushabh Lathia
<rushabh.lathia@gmail.com> wrote:
> Hi,
>
> Consider the below testcase:
>
> CREATE TABLE tab(
>   c1 INT NOT NULL,
>   c2 INT NOT NULL
> );
> INSERT INTO tab VALUES (1, 2);
> INSERT INTO tab VALUES (2, 1);
> INSERT INTO tab VALUES (1, 2);
>
>
> case 1:
>
> SELECT c.c1, c.c2 from tab C WHERE c.c2 = ANY (
>     SELECT 1 FROM tab A WHERE a.c2 IN (
>       SELECT 1 FROM tab B WHERE a.c1 = c.c1
>       GROUP BY rollup(a.c1)
>     )
>     GROUP BY cube(c.c2)
>   )
>   GROUP BY grouping sets(c.c1, c.c2)
>   ORDER BY 1, 2 DESC;
> ERROR:  ORDER/GROUP BY expression not found in targetlist
>
> case 2:
>
> create sequence s;
> SELECT setval('s', max(100)) from tab;
> ERROR:  ORDER/GROUP BY expression not found in targetlist

The following give the same error:

select max(100) from tab;
select max((select 1)) from tab;

Thanks,
Amit



Re: ERROR: ORDER/GROUP BY expression not found in targetlist

От
Tom Lane
Дата:
Rushabh Lathia <rushabh.lathia@gmail.com> writes:
> SELECT setval('s', max(100)) from tab;
> ERROR:  ORDER/GROUP BY expression not found in targetlist

Fixed, thanks for the report!
        regards, tom lane



Re: ERROR: ORDER/GROUP BY expression not found in targetlist

От
Rushabh Lathia
Дата:
Thanks Tom.

I performed testing with the latest commit and test are
running fine.

On Tue, Jun 28, 2016 at 8:14 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Rushabh Lathia <rushabh.lathia@gmail.com> writes:
> SELECT setval('s', max(100)) from tab;
> ERROR:  ORDER/GROUP BY expression not found in targetlist

Fixed, thanks for the report!

                        regards, tom lane



--
Rushabh Lathia