c1 integer,
c2 text,
c3 date
-);
+) WITH OIDS;
COPY t1 FROM stdin;
CREATE TABLE t2(
c1 integer,
c1 integer OPTIONS (colname 'invalid'),
c2 text OPTIONS (colname 'C2'),
c3 date
-) SERVER loopback1 OPTIONS (relname 't1');
+) SERVER loopback1 WITH OIDS OPTIONS (relname 't1');
ALTER FOREIGN TABLE ft1 ALTER COLUMN c1 OPTIONS (SET colname 'C1');
ALTER FOREIGN TABLE ft1 ALTER COLUMN c2 OPTIONS (DROP colname);
CREATE FOREIGN TABLE ft2 (
c3 date
) SERVER loopback2 OPTIONS (relname 'invalid');
-- simple query and connection caching
-SELECT * FROM ft1 ORDER BY c1;
+SELECT ft1.* FROM ft1 JOIN t1 ON ((t1.c1, t1.oid) = (ft1.c1, ft1.oid)) ORDER BY c1;
c1 | c2 | c3
----+-----+------------
1 | foo | 01-01-1970
-- WHERE clause push-down
set client_min_messages = debug1;
SELECT * FROM ft1 WHERE c1 = 1 AND c2 = lower('FOO') AND c3 < now();
-DEBUG: deparsed SQL is "SELECT C1, c2, c3 FROM public.t1 ft1 WHERE ((c1 = 1) AND (c2 = 'foo'::text))"
+DEBUG: deparsed SQL is "SELECT C1, c2, c3, oid FROM public.t1 ft1 WHERE ((c1 = 1) AND (c2 = 'foo'::text))"
c1 | c2 | c3
----+-----+------------
1 | foo | 01-01-1970
first = false;
}
+ /* Add oid system attribute if any on local side. */
+ if (tupdesc->tdhasoid)
+ {
+ if (!first)
+ appendStringInfo(sql, ", oid");
+ else
+ appendStringInfo(sql, "oid");
+ first = false;
+ }
+
/* if target list is composed only of system attributes, add dummy column */
if (first)
appendStringInfoString(sql, "NULL");
for (attnum = 0, i = 0; i < tupdesc->natts; i++)
if (!attrs[i]->attisdropped)
attnum++;
+ if (tupdesc->tdhasoid)
+ attnum++;
/* check result and tuple descriptor have the same number of columns */
if (attnum > 0 && attnum != nfields)
{
int j;
HeapTuple tuple;
+ Oid oid = InvalidOid; /* oid of the tuple */
CHECK_FOR_INTERRUPTS();
values[i] = PQgetvalue(res, row, j);
j++;
}
+
+ /* Get oid if any. Now j points the oid field of PGresult. */
+ if (tupdesc->tdhasoid)
+ {
+ if (!PQgetisnull(res, row, j))
+ {
+ oid = DatumGetObjectId(DirectFunctionCall1(oidin,
+ CStringGetDatum(PQgetvalue(res, row, j))));
+ }
+ }
}
else
{
values[0] = PQcmdStatus(res);
}
- /* build the tuple and put it into the tuplestore. */
+ /* build the tuple, set oid if any, and put it into the tuplestore. */
tuple = BuildTupleFromCStrings(attinmeta, values);
+ if (tupdesc->tdhasoid)
+ HeapTupleSetOid(tuple, oid);
tuplestore_puttuple(tupstore, tuple);
}
c1 integer,
c2 text,
c3 date
-);
+) WITH OIDS;
COPY t1 FROM stdin;
1 foo 1970-01-01
c1 integer OPTIONS (colname 'invalid'),
c2 text OPTIONS (colname 'C2'),
c3 date
-) SERVER loopback1 OPTIONS (relname 't1');
+) SERVER loopback1 WITH OIDS OPTIONS (relname 't1');
ALTER FOREIGN TABLE ft1 ALTER COLUMN c1 OPTIONS (SET colname 'C1');
ALTER FOREIGN TABLE ft1 ALTER COLUMN c2 OPTIONS (DROP colname);
) SERVER loopback2 OPTIONS (relname 'invalid');
-- simple query and connection caching
-SELECT * FROM ft1 ORDER BY c1;
+SELECT ft1.* FROM ft1 JOIN t1 ON ((t1.c1, t1.oid) = (ft1.c1, ft1.oid)) ORDER BY c1;
SELECT * FROM ft2 ORDER BY c1; -- ERROR
ALTER USER MAPPING FOR PUBLIC SERVER loopback2 OPTIONS (DROP user);
SELECT * FROM ft2 ORDER BY c1; -- ERROR