Skip to content

Commit

Permalink
Alter AddForeignUpdateTargets to conform to new Pg14 method of provid…
Browse files Browse the repository at this point in the history
…ing row identifiers to modifying queries, closes #231
  • Loading branch information
pramsey committed Jun 22, 2022
1 parent f828a8f commit 3763517
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
31 changes: 27 additions & 4 deletions ogr_fdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -2489,6 +2489,7 @@ ogrGetFidColumn(const TupleDesc td)
* there could always be a virtual fid travelling with the queries,
* and the FDW table itself wouldn't need such a column?
*/

#if PG_VERSION_NUM >= 140000
static void
ogrAddForeignUpdateTargets(PlannerInfo* planinfo,
Expand All @@ -2497,14 +2498,36 @@ ogrAddForeignUpdateTargets(PlannerInfo* planinfo,
Relation target_relation)
{
Query* parsetree = planinfo->parse;
#else
Form_pg_attribute att;
Var* var;
TupleDesc tupdesc = target_relation->rd_att;
int fid_column = ogrGetFidColumn(tupdesc);

elog(DEBUG3, "%s: entered function", __func__);

if (fid_column < 0)
{
elog(ERROR, "table '%s' does not have a 'fid' column", RelationGetRelationName(target_relation));
}

att = &tupdesc->attrs[fid_column];
/* Make a Var representing the desired value */
var = makeVar(parsetree->resultRelation,
att->attnum,
att->atttypid,
att->atttypmod,
att->attcollation,
0);

add_row_identity_var(planinfo, var, rte_index, "fid");
}
#else /* PG_VERSION_NUM < 140000 */

static void
ogrAddForeignUpdateTargets(Query* parsetree,
RangeTblEntry* target_rte,
Relation target_relation)
{
#endif
ListCell* cell;
Form_pg_attribute att;
Var* var;
Expand Down Expand Up @@ -2545,10 +2568,10 @@ ogrAddForeignUpdateTargets(Query* parsetree,
TargetEntry* target = (TargetEntry*) lfirst(cell);
elog(DEBUG4, "parsetree->targetList %s:%d", target->resname, target->resno);
}
}
#endif

return;

}

/*
* ogrBeginForeignModify
Expand Down
1 change: 1 addition & 0 deletions ogr_fdw.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h"
#include "optimizer/appendinfo.h"
#include "optimizer/clauses.h"
#include "optimizer/cost.h"
#include "optimizer/pathnode.h"
Expand Down

0 comments on commit 3763517

Please sign in to comment.