postgres-github.git / summary / log / commit / refs

commit    8d829f5a0203ed4395e2d4d3931cd225a00c1b14
Author:   Richard Guo <rguo@postgresql.org>
Date:     Fri May 01 00:42:00 2026 +0000

    Fix JSON_ARRAY(query) empty set handling and view deparsing
    
    According to the SQL/JSON standard, JSON_ARRAY(query) must return an
    empty JSON array ('[]') when the subquery returns zero rows.
    
    Previously, the parser rewrote JSON_ARRAY(query) into a JSON_ARRAYAGG
    aggregate function.  Because this aggregate evaluates to NULL over an
    empty set without a GROUP BY clause, the constructor erroneously
    returned NULL.  Additionally, this premature rewrite baked physical
    implementation details into the catalog, preventing ruleutils.c from
    deparsing the original syntax for views.
    
    This patch resolves both issues by introducing a new
    JSCTOR_JSON_ARRAY_QUERY constructor type.  The parser builds the
    executable form --- a COALESCE-wrapped JSON_ARRAYAGG subquery --- from
    raw parse nodes via transformExprRecurse, and stores it in the func
    field.  The original transformed Query is kept in a new orig_query
    field so that ruleutils.c can deparse the original syntax for views.
    During planning, eval_const_expressions replaces the node with the
    pre-built func expression.
    
    The deparsing issue was reported by Tom Lane.
    
    Bump catalog version.
    
    Bug: #19418
    Reported-by: Lukas Eder <lukas.eder@gmail.com>
    Author: Richard Guo <guofenglinux@gmail.com>
    Reviewed-by: Amit Langote <amitlangote09@gmail.com>
    Discussion: https://postgr.es/m/19418-591ba1f29862ef5b@postgresql.org

[parent: 6ca631b99012]