Hi hackers,


I found that dumped view SQL failed to execute due to the explicit cast

of negative number, and I took a look at the defined SQL in view and then

found -1 in the group by clause. I suppose it’s the main reason the sql

cannot be executed and raised ERROR "GROUP BY position -1 is not in select list"



postgres=# create view v1 as select * from t1 group by a,b,-1::int;

CREATE VIEW

postgres=# \d+ v1;

                             View "public.v1"

 Column |  Type   | Collation | Nullable | Default | Storage | Description

--------+---------+-----------+----------+---------+---------+-------------

 a      | integer |           |          |         | plain   |

 b      | integer |           |          |         | plain   |

View definition:

 SELECT a,

    b

   FROM t1

  GROUP BY a, b, (- 1);



After exploring codes, I suppose we should treat operator plus constant

as -'nnn'::typename instead of const, my patch just did this by handling

Opexpr especially, but I am not sure it’s the best way or not, BTW do you

guys have any suggestions and another approach?



--
Best Regards,
Haotian

Attachment: v1-0001-fix-dump-view-fails-with-group-by-clause.patch
Description: v1-0001-fix-dump-view-fails-with-group-by-clause.patch

Reply via email to