postgresql/contrib/postgres_fdw
David Rowley 6a9e2cb2b4 Fix deparsing of Consts in postgres_fdw ORDER BY
For UNION ALL queries where a union child query contained a foreign
table, if the targetlist of that query contained a constant, and the
top-level query performed an ORDER BY which contained the column for the
constant value, then postgres_fdw would find the EquivalenceMember with
the Const and then try to produce an ORDER BY containing that Const.

This caused problems with INT typed Consts as these could appear to be
requests to order by an ordinal column position rather than the constant
value.  This could lead to either an error such as:

ERROR:  ORDER BY position <int const> is not in select list

or worse, if the constant value is a valid column, then we could just
sort by the wrong column altogether.

Here we fix this issue by just not including these Consts in the ORDER
BY clause.

In passing, add a new section for testing ORDER BY in the postgres_fdw
tests and move two existing tests which were misplaced in the WHERE
clause testing section into it.

Reported-by: Michał Kłeczek
Reviewed-by: Ashutosh Bapat, Richard Guo
Bug: #18381
Discussion: https://postgr.es/m/0714C8B8-8D82-4ABB-9F8D-A0C3657E7B6E%40kleczek.org
Discussion: https://postgr.es/m/18381-137456acd168bf93%40postgresql.org
Backpatch-through: 12, oldest supported version
2024-03-11 12:27:46 +13:00
..
expected Fix deparsing of Consts in postgres_fdw ORDER BY 2024-03-11 12:27:46 +13:00
sql Fix deparsing of Consts in postgres_fdw ORDER BY 2024-03-11 12:27:46 +13:00
.gitignore
connection.c rename "gss_accept_deleg" to "gss_accept_delegation". 2023-05-20 21:32:54 -04:00
deparse.c Fix deparsing of Consts in postgres_fdw ORDER BY 2024-03-11 12:27:46 +13:00
Makefile postgres_fdw: Add function to list cached connections to foreign servers. 2021-01-18 15:11:08 +09:00
meson.build Update copyright for 2023 2023-01-02 15:00:37 -05:00
option.c Expand some more uses of "deleg" to "delegation" or "delegated". 2023-05-21 10:55:18 -04:00
postgres_fdw--1.0--1.1.sql postgres_fdw: Add functions to discard cached connections. 2021-01-26 15:35:54 +09:00
postgres_fdw--1.0.sql
postgres_fdw.c Fix filtering of "cloned" outer-join quals some more. 2023-05-25 10:28:33 -04:00
postgres_fdw.control postgres_fdw: Add function to list cached connections to foreign servers. 2021-01-18 15:11:08 +09:00
postgres_fdw.h Check relkind before using TABLESAMPLE in postgres_fdw 2023-01-07 14:39:33 +01:00
shippable.c Pre-beta mechanical code beautification. 2023-05-19 17:24:48 -04:00