Home Explore Blog CI



postgresql

8th chunk of `doc/src/sgml/fdwhandler.sgml`
5587e332c22197a14f5daf98459109a3112b75f498e3e4620000000100000fa0
   that <structname>Var</structname>s that are identical except for
     the <structfield>varno</structfield> field can and should share a
     column name.
     The core system uses the junk column names
     <literal>tableoid</literal> for a
     table's <structfield>tableoid</structfield> column,
     <literal>ctid</literal>
     or <literal>ctid<replaceable>N</replaceable></literal>
     for <structfield>ctid</structfield>,
     <literal>wholerow</literal>
     for a whole-row <structname>Var</structname> marked with
     <structfield>vartype</structfield> = <type>RECORD</type>,
     and <literal>wholerow<replaceable>N</replaceable></literal>
     for a whole-row <structname>Var</structname> with
     <structfield>vartype</structfield> equal to the table's declared row type.
     Re-use these names when you can (the planner will combine duplicate
     requests for identical junk columns).  If you need another kind of
     junk column besides these, it might be wise to choose a name prefixed
     with your extension name, to avoid conflicts against other FDWs.
    </para>

    <para>
     If the <function>AddForeignUpdateTargets</function> pointer is set to
     <literal>NULL</literal>, no extra target expressions are added.
     (This will make it impossible to implement <command>DELETE</command>
     operations, though <command>UPDATE</command> may still be feasible if the FDW
     relies on an unchanging primary key to identify rows.)
    </para>

    <para>
<programlisting>
List *
PlanForeignModify(PlannerInfo *root,
                  ModifyTable *plan,
                  Index resultRelation,
                  int subplan_index);
</programlisting>

     Perform any additional planning actions needed for an insert, update, or
     delete on a foreign table.  This function generates the FDW-private
     information that will be attached to the <structname>ModifyTable</structname> plan
     node that performs the update action.  This private information must
     have the form of a <literal>List</literal>, and will be delivered to
     <function>BeginForeignModify</function> during the execution stage.
    </para>

    <para>
     <literal>root</literal> is the planner's global information about the query.
     <literal>plan</literal> is the <structname>ModifyTable</structname> plan node, which is
     complete except for the <structfield>fdwPrivLists</structfield> field.
     <literal>resultRelation</literal> identifies the target foreign table by its
     range table index.  <literal>subplan_index</literal> identifies which target of
     the <structname>ModifyTable</structname> plan node this is, counting from zero;
     use this if you want to index into per-target-relation substructures of the
     <literal>plan</literal> node.
    </para>

    <para>
     See <xref linkend="fdw-planning"/> for additional information.
    </para>

    <para>
     If the <function>PlanForeignModify</function> pointer is set to
     <literal>NULL</literal>, no additional plan-time actions are taken, and the
     <literal>fdw_private</literal> list delivered to
     <function>BeginForeignModify</function> will be NIL.
    </para>

    <para>
<programlisting>
void
BeginForeignModify(ModifyTableState *mtstate,
                   ResultRelInfo *rinfo,
                   List *fdw_private,
                   int subplan_index,
                   int eflags);
</programlisting>

     Begin executing a foreign table modification operation.  This routine is
     called during executor startup.  It should perform any initialization
     needed prior to the actual table modifications.  Subsequently,
     <function>ExecForeignInsert/ExecForeignBatchInsert</function>,
     <function>ExecForeignUpdate</function> or
     <function>ExecForeignDelete</function> will be called for tuple(s) to be
     inserted, updated, or deleted.
    </para>

    <para>
     <literal>mtstate</literal> is the overall state of the
     <structname>ModifyTable</structname>

Title: FDW Routines for Updating Foreign Tables: AddForeignUpdateTargets, PlanForeignModify, and BeginForeignModify
Summary
This section continues discussing FDW routines for updating foreign tables, elaborating on the `AddForeignUpdateTargets` function and its usage with junk column names such as `tableoid`, `ctid`, and `wholerow` for identifying rows. It also describes the `PlanForeignModify` function, which performs additional planning actions for insert, update, or delete operations on a foreign table, generating FDW-private information attached to the `ModifyTable` plan node. Finally, the `BeginForeignModify` function is introduced for initializing a foreign table modification operation during executor startup, preparing for subsequent calls to `ExecForeignInsert`, `ExecForeignUpdate`, or `ExecForeignDelete`.