summaryrefslogtreecommitdiff
path: root/doc/src/sgml/fdwhandler.sgml
diff options
context:
space:
mode:
Diffstat (limited to 'doc/src/sgml/fdwhandler.sgml')
-rw-r--r--doc/src/sgml/fdwhandler.sgml65
1 files changed, 37 insertions, 28 deletions
diff --git a/doc/src/sgml/fdwhandler.sgml b/doc/src/sgml/fdwhandler.sgml
index 635c9ec559a..0f2397df497 100644
--- a/doc/src/sgml/fdwhandler.sgml
+++ b/doc/src/sgml/fdwhandler.sgml
@@ -424,7 +424,8 @@ GetForeignUpperPaths(PlannerInfo *root,
<para>
<programlisting>
void
-AddForeignUpdateTargets(Query *parsetree,
+AddForeignUpdateTargets(PlannerInfo *root,
+ Index rtindex,
RangeTblEntry *target_rte,
Relation target_relation);
</programlisting>
@@ -440,27 +441,31 @@ AddForeignUpdateTargets(Query *parsetree,
</para>
<para>
- To do that, add <structname>TargetEntry</structname> items to
- <literal>parsetree-&gt;targetList</literal>, containing expressions for the
- extra values to be fetched. Each such entry must be marked
- <structfield>resjunk</structfield> = <literal>true</literal>, and must have a distinct
- <structfield>resname</structfield> that will identify it at execution time.
- Avoid using names matching <literal>ctid<replaceable>N</replaceable></literal>,
- <literal>wholerow</literal>, or
- <literal>wholerow<replaceable>N</replaceable></literal>, as the core system can
- generate junk columns of these names.
- If the extra expressions are more complex than simple Vars, they
- must be run through <function>eval_const_expressions</function>
- before adding them to the target list.
- </para>
-
- <para>
- Although this function is called during planning, the
- information provided is a bit different from that available to other
- planning routines.
- <literal>parsetree</literal> is the parse tree for the <command>UPDATE</command> or
- <command>DELETE</command> command, while <literal>target_rte</literal> and
- <literal>target_relation</literal> describe the target foreign table.
+ To do that, construct a <structname>Var</structname> representing
+ an extra value you need, and pass it
+ to <function>add_row_identity_var</function>, along with a name for
+ the junk column. (You can do this more than once if several columns
+ are needed.) You must choose a distinct junk column name for each
+ different <structname>Var</structname> you need, except
+ 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 rowtype.
+ 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>
@@ -495,8 +500,8 @@ PlanForeignModify(PlannerInfo *root,
<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 <literal>plan-&gt;plans</literal> or other
- substructure of the <literal>plan</literal> node.
+ use this if you want to index into per-target-relation substructures of the
+ <literal>plan</literal> node.
</para>
<para>
@@ -703,10 +708,14 @@ ExecForeignUpdate(EState *estate,
<literal>slot</literal> contains the new data for the tuple; it will match the
row-type definition of the foreign table.
<literal>planSlot</literal> contains the tuple that was generated by the
- <structname>ModifyTable</structname> plan node's subplan; it differs from
- <literal>slot</literal> in possibly containing additional <quote>junk</quote>
- columns. In particular, any junk columns that were requested by
- <function>AddForeignUpdateTargets</function> will be available from this slot.
+ <structname>ModifyTable</structname> plan node's subplan. Unlike
+ <literal>slot</literal>, this tuple contains only the new values for
+ columns changed by the query, so do not rely on attribute numbers of the
+ foreign table to index into <literal>planSlot</literal>.
+ Also, <literal>planSlot</literal> typically contains
+ additional <quote>junk</quote> columns. In particular, any junk columns
+ that were requested by <function>AddForeignUpdateTargets</function> will
+ be available from this slot.
</para>
<para>