Re: COPY WHERE clause generated/system column reference - Mailing list pgsql-hackers

From jian he
Subject Re: COPY WHERE clause generated/system column reference
Date
Msg-id CACJufxGM=umA-qLkCOX7nPDJ5=xuum4EnK8h3f13vztVZ8jfUA@mail.gmail.com
Whole thread Raw
In response to Re: COPY WHERE clause generated/system column reference  (Kirill Reshke <reshkekirill@gmail.com>)
List pgsql-hackers
On Tue, Oct 28, 2025 at 2:02 AM Kirill Reshke <reshkekirill@gmail.com> wrote:
>
> Small comment: in 0002:
>
> > + if (has_stored_generated)
> > + ExecComputeStoredGenerated(resultRelInfo, estate, myslot,
> > +   CMD_INSERT);
>
> Should we use CMD_UTILITY here? Comment in nodes.h suggests so. Also,
> ExecComputeStoredGenerated only check for equality with CMD_UPDATE, so
> this is just a cosmetic change.
>
hi.

use CMD_UTILITY will also work as expected.
ExecComputeStoredGenerated expects the command type (cmdtype) to be either
UPDATE or INSERT.

in ExecComputeStoredGenerated, we have:
    if (cmdtype == CMD_UPDATE)
    else
    {
        if (resultRelInfo->ri_GeneratedExprsI == NULL)
            ExecInitGenerated(resultRelInfo, estate, cmdtype);
        /* Early exit is impossible given the prior Assert */
        Assert(resultRelInfo->ri_NumGeneratedNeededI > 0);
        ri_GeneratedExprs = resultRelInfo->ri_GeneratedExprsI;
    }

in struct ResultRelInfo also has comments like:
    /*
     * Arrays of stored generated columns ExprStates for INSERT/UPDATE/MERGE.
     */
    ExprState **ri_GeneratedExprsI;
    ExprState **ri_GeneratedExprsU;

I think using CMD_INSERT should be fine. Also, note that below
ExecComputeStoredGenerated uses CMD_INSERT too.



pgsql-hackers by date:

Previous
From: Alexander Lakhin
Date:
Subject: Re: GNU/Hurd portability patches
Next
From: Rahila Syed
Date:
Subject: Re: Enhancing Memory Context Statistics Reporting