aboutsummaryrefslogtreecommitdiff
path: root/contrib/postgres_fdw/postgres_fdw.c
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2016-08-26 16:33:57 +0300
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2016-08-26 16:33:57 +0300
commitae025a15988f5491903cd3a2075f308c2773f711 (patch)
treefb69002b57eb876b8690157eee1245996214a87b /contrib/postgres_fdw/postgres_fdw.c
parent2533ff0aa518d4d31391db279cf08e538fae5931 (diff)
downloadpostgresql-ae025a15988f5491903cd3a2075f308c2773f711.tar.gz
postgresql-ae025a15988f5491903cd3a2075f308c2773f711.zip
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>
Diffstat (limited to 'contrib/postgres_fdw/postgres_fdw.c')
-rw-r--r--contrib/postgres_fdw/postgres_fdw.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c
index bfd81c46c86..b92f29958f3 100644
--- a/contrib/postgres_fdw/postgres_fdw.c
+++ b/contrib/postgres_fdw/postgres_fdw.c
@@ -4374,6 +4374,7 @@ make_tuple_from_result_row(PGresult *res,
Datum *values;
bool *nulls;
ItemPointer ctid = NULL;
+ Oid oid = InvalidOid;
ConversionLocation errpos;
ErrorContextCallback errcallback;
MemoryContext oldcontext;
@@ -4431,7 +4432,11 @@ make_tuple_from_result_row(PGresult *res,
else
valstr = PQgetvalue(res, row, j);
- /* convert value to internal representation */
+ /*
+ * convert value to internal representation
+ *
+ * Note: we ignore system columns other than ctid and oid in result
+ */
errpos.cur_attno = i;
if (i > 0)
{
@@ -4446,7 +4451,7 @@ make_tuple_from_result_row(PGresult *res,
}
else if (i == SelfItemPointerAttributeNumber)
{
- /* ctid --- note we ignore any other system column in result */
+ /* ctid */
if (valstr != NULL)
{
Datum datum;
@@ -4455,6 +4460,17 @@ make_tuple_from_result_row(PGresult *res,
ctid = (ItemPointer) DatumGetPointer(datum);
}
}
+ else if (i == ObjectIdAttributeNumber)
+ {
+ /* oid */
+ if (valstr != NULL)
+ {
+ Datum datum;
+
+ datum = DirectFunctionCall1(oidin, CStringGetDatum(valstr));
+ oid = DatumGetObjectId(datum);
+ }
+ }
errpos.cur_attno = 0;
j++;
@@ -4498,6 +4514,12 @@ make_tuple_from_result_row(PGresult *res,
HeapTupleHeaderSetXmin(tuple->t_data, InvalidTransactionId);
HeapTupleHeaderSetCmin(tuple->t_data, InvalidTransactionId);
+ /*
+ * If we have an OID to return, install it.
+ */
+ if (OidIsValid(oid))
+ HeapTupleSetOid(tuple, oid);
+
/* Clean up */
MemoryContextReset(temp_context);
@@ -4525,6 +4547,8 @@ conversion_error_callback(void *arg)
attname = NameStr(tupdesc->attrs[errpos->cur_attno - 1]->attname);
else if (errpos->cur_attno == SelfItemPointerAttributeNumber)
attname = "ctid";
+ else if (errpos->cur_attno == ObjectIdAttributeNumber)
+ attname = "oid";
relname = RelationGetRelationName(errpos->rel);
}