On Thu, Jul 24, 2025, 09:22 PG Doc comments form <nore...@postgresql.org> wrote:
> The following documentation comment has been logged on the website: > > Page: https://www.postgresql.org/docs/17/queries-union.html > Description: > > When combining queries with UNION, INTERSECT, or EXCEPT, columns are > matched > in the order in which they occur, and not by column name. This can be > unexpected, and I think it would be helpful to call it out explicitly in > the > documentation. The docs never imply that matching by name is a thing in SQL generally. People make assumptions all the time and we generally don't try and write to anticipate and disabuse people of random assumptions. We instead document how things work. We don't document here that all column names in both queries must be identical which is what your assumption would require. The existing wording strongly implies that corresponding matches are done by index. Then concretely an example on that page unions columns, A and X, this clearly showing that names are immaterial and, like the requirements state, data type matching columns at each position are paired. I could maybe see adding "position" somewhere but calling it out with a warning seems unnecessary. Even if one gets confused it is immediately obvious when checking the result that there is an issue. David J.