If an expression containing an aggregate is evaluated above the plan node that computes the aggregate, as happens with window functions or with expressions postponed to above the final sort, setrefs.c replaces the Aggref or WindowFunc with a Var referencing the lower node's output. For SQL/JSON aggregates such as JSON_ARRAYAGG and JSON_OBJECTAGG, deparsing the containing JsonConstructorExpr then failed with "invalid JsonConstructorExpr underlying node type", since get_json_agg_constructor() did not expect a Var there. Fix by resolving the Var back to the underlying Aggref or WindowFunc and deparsing the constructor as if the aggregate were computed at the current node. The JsonConstructorExpr retains the RETURNING clause and the ABSENT/NULL ON NULL and WITH UNIQUE options, and the arguments come from the resolved aggregate, so the original JSON aggregate syntax is reproduced in full. This mirrors how get_agg_expr() already looks through such a Var when deparsing a combining aggregate. Reported-by: Thom Brown <thom@linux.com> Author: Richard Guo <guofenglinux@gmail.com> Discussion: https://postgr.es/m/CAA-aLv5QYTaMOk=Qhv6cgwceeHETZV8YJvWZ_rH+yVZCuchATA@mail.gmail.com Backpatch-through: 16 |
||
|---|---|---|
| .github | ||
| config | ||
| contrib | ||
| doc | ||
| src | ||
| .dir-locals.el | ||
| .editorconfig | ||
| .git-blame-ignore-revs | ||
| .gitattributes | ||
| .gitignore | ||
| .mailmap | ||
| aclocal.m4 | ||
| configure | ||
| configure.ac | ||
| COPYRIGHT | ||
| GNUmakefile.in | ||
| HISTORY | ||
| Makefile | ||
| meson.build | ||
| meson_options.txt | ||
| README.md | ||
PostgreSQL Database Management System
This directory contains the source code distribution of the PostgreSQL database management system.
PostgreSQL is an advanced object-relational database management system that supports an extended subset of the SQL standard, including transactions, foreign keys, subqueries, triggers, user-defined types and functions. This distribution also contains C language bindings.
Copyright and license information can be found in the file COPYRIGHT.
General documentation about this version of PostgreSQL can be found at https://www.postgresql.org/docs/19/. In particular, information about building PostgreSQL from the source code can be found at https://www.postgresql.org/docs/19/installation.html.
The latest version of this software, and related software, may be obtained at https://www.postgresql.org/download/. For more information look at our web site located at https://www.postgresql.org/.