mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Support OID system column in postgres_fdw.
You can use ALTER FOREIGN TABLE SET WITH OIDS on a foreign table, but the oid column read out as zeros, because the postgres_fdw didn't know about it. Teach postgres_fdw how to fetch it. Etsuro Fujita, with an additional test case by me. Discussion: <56E90A76.5000503@lab.ntt.co.jp>
This commit is contained in:
@ -287,13 +287,14 @@ foreign_expr_walker(Node *node,
|
||||
/* Var belongs to foreign table */
|
||||
|
||||
/*
|
||||
* System columns other than ctid should not be sent to
|
||||
* the remote, since we don't make any effort to ensure
|
||||
* that local and remote values match (tableoid, in
|
||||
* System columns other than ctid and oid should not be
|
||||
* sent to the remote, since we don't make any effort to
|
||||
* ensure that local and remote values match (tableoid, in
|
||||
* particular, almost certainly doesn't match).
|
||||
*/
|
||||
if (var->varattno < 0 &&
|
||||
var->varattno != SelfItemPointerAttributeNumber)
|
||||
var->varattno != SelfItemPointerAttributeNumber &&
|
||||
var->varattno != ObjectIdAttributeNumber)
|
||||
return false;
|
||||
|
||||
/* Else check the collation */
|
||||
@ -913,8 +914,8 @@ deparseTargetList(StringInfo buf,
|
||||
}
|
||||
|
||||
/*
|
||||
* Add ctid if needed. We currently don't support retrieving any other
|
||||
* system columns.
|
||||
* Add ctid and oid if needed. We currently don't support retrieving any
|
||||
* other system columns.
|
||||
*/
|
||||
if (bms_is_member(SelfItemPointerAttributeNumber - FirstLowInvalidHeapAttributeNumber,
|
||||
attrs_used))
|
||||
@ -932,6 +933,22 @@ deparseTargetList(StringInfo buf,
|
||||
*retrieved_attrs = lappend_int(*retrieved_attrs,
|
||||
SelfItemPointerAttributeNumber);
|
||||
}
|
||||
if (bms_is_member(ObjectIdAttributeNumber - FirstLowInvalidHeapAttributeNumber,
|
||||
attrs_used))
|
||||
{
|
||||
if (!first)
|
||||
appendStringInfoString(buf, ", ");
|
||||
else if (is_returning)
|
||||
appendStringInfoString(buf, " RETURNING ");
|
||||
first = false;
|
||||
|
||||
if (qualify_col)
|
||||
ADD_REL_QUALIFIER(buf, rtindex);
|
||||
appendStringInfoString(buf, "oid");
|
||||
|
||||
*retrieved_attrs = lappend_int(*retrieved_attrs,
|
||||
ObjectIdAttributeNumber);
|
||||
}
|
||||
|
||||
/* Don't generate bad syntax if no undropped columns */
|
||||
if (first && !is_returning)
|
||||
@ -1574,13 +1591,19 @@ deparseColumnRef(StringInfo buf, int varno, int varattno, PlannerInfo *root,
|
||||
{
|
||||
RangeTblEntry *rte;
|
||||
|
||||
/* We support fetching the remote side's CTID and OID. */
|
||||
if (varattno == SelfItemPointerAttributeNumber)
|
||||
{
|
||||
/* We support fetching the remote side's CTID. */
|
||||
if (qualify_col)
|
||||
ADD_REL_QUALIFIER(buf, varno);
|
||||
appendStringInfoString(buf, "ctid");
|
||||
}
|
||||
else if (varattno == ObjectIdAttributeNumber)
|
||||
{
|
||||
if (qualify_col)
|
||||
ADD_REL_QUALIFIER(buf, varno);
|
||||
appendStringInfoString(buf, "oid");
|
||||
}
|
||||
else if (varattno < 0)
|
||||
{
|
||||
/*
|
||||
|
Reference in New Issue
Block a user