Commit 86437ddf authored by Robert Haas's avatar Robert Haas

postgres_fdw: Fix cache lookup failure while creating error context.

This is fallout from join pushdown; get_relid_attribute_name can't
handle an attribute number of 0, indicating a whole-row reference,
and shouldn't be called in that case.

Etsuro Fujita, reviewed by Ashutosh Bapat
parent 5f3499b2
...@@ -2591,6 +2591,9 @@ CONTEXT: column "c8" of foreign table "ft1" ...@@ -2591,6 +2591,9 @@ CONTEXT: column "c8" of foreign table "ft1"
SELECT ft1.c1, ft2.c2, ft1.c8 FROM ft1, ft2 WHERE ft1.c1 = ft2.c1 AND ft1.c1 = 1; -- ERROR SELECT ft1.c1, ft2.c2, ft1.c8 FROM ft1, ft2 WHERE ft1.c1 = ft2.c1 AND ft1.c1 = 1; -- ERROR
ERROR: invalid input syntax for integer: "foo" ERROR: invalid input syntax for integer: "foo"
CONTEXT: column "c8" of foreign table "ft1" CONTEXT: column "c8" of foreign table "ft1"
SELECT ft1.c1, ft2.c2, ft1 FROM ft1, ft2 WHERE ft1.c1 = ft2.c1 AND ft1.c1 = 1; -- ERROR
ERROR: invalid input syntax for integer: "foo"
CONTEXT: whole-row reference to foreign table "ft1"
ALTER FOREIGN TABLE ft1 ALTER COLUMN c8 TYPE user_enum; ALTER FOREIGN TABLE ft1 ALTER COLUMN c8 TYPE user_enum;
-- =================================================================== -- ===================================================================
-- subtransaction -- subtransaction
......
...@@ -4528,6 +4528,7 @@ conversion_error_callback(void *arg) ...@@ -4528,6 +4528,7 @@ conversion_error_callback(void *arg)
{ {
const char *attname = NULL; const char *attname = NULL;
const char *relname = NULL; const char *relname = NULL;
bool is_wholerow = false;
ConversionLocation *errpos = (ConversionLocation *) arg; ConversionLocation *errpos = (ConversionLocation *) arg;
if (errpos->rel) if (errpos->rel)
...@@ -4560,12 +4561,22 @@ conversion_error_callback(void *arg) ...@@ -4560,12 +4561,22 @@ conversion_error_callback(void *arg)
Assert(IsA(var, Var)); Assert(IsA(var, Var));
rte = rt_fetch(var->varno, estate->es_range_table); rte = rt_fetch(var->varno, estate->es_range_table);
relname = get_rel_name(rte->relid);
if (var->varattno == 0)
is_wholerow = true;
else
attname = get_relid_attribute_name(rte->relid, var->varattno); attname = get_relid_attribute_name(rte->relid, var->varattno);
relname = get_rel_name(rte->relid);
} }
if (attname && relname) if (relname)
{
if (is_wholerow)
errcontext("whole-row reference to foreign table \"%s\"", relname);
else if (attname)
errcontext("column \"%s\" of foreign table \"%s\"", attname, relname); errcontext("column \"%s\" of foreign table \"%s\"", attname, relname);
}
} }
/* /*
......
...@@ -627,6 +627,7 @@ DROP FUNCTION f_test(int); ...@@ -627,6 +627,7 @@ DROP FUNCTION f_test(int);
ALTER FOREIGN TABLE ft1 ALTER COLUMN c8 TYPE int; ALTER FOREIGN TABLE ft1 ALTER COLUMN c8 TYPE int;
SELECT * FROM ft1 WHERE c1 = 1; -- ERROR SELECT * FROM ft1 WHERE c1 = 1; -- ERROR
SELECT ft1.c1, ft2.c2, ft1.c8 FROM ft1, ft2 WHERE ft1.c1 = ft2.c1 AND ft1.c1 = 1; -- ERROR SELECT ft1.c1, ft2.c2, ft1.c8 FROM ft1, ft2 WHERE ft1.c1 = ft2.c1 AND ft1.c1 = 1; -- ERROR
SELECT ft1.c1, ft2.c2, ft1 FROM ft1, ft2 WHERE ft1.c1 = ft2.c1 AND ft1.c1 = 1; -- ERROR
ALTER FOREIGN TABLE ft1 ALTER COLUMN c8 TYPE user_enum; ALTER FOREIGN TABLE ft1 ALTER COLUMN c8 TYPE user_enum;
-- =================================================================== -- ===================================================================
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment