Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 86437dd

Browse files
committed
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
1 parent 5f3499b commit 86437dd

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

contrib/postgres_fdw/expected/postgres_fdw.out

+3
Original file line numberDiff line numberDiff line change
@@ -2591,6 +2591,9 @@ CONTEXT: column "c8" of foreign table "ft1"
25912591
SELECT ft1.c1, ft2.c2, ft1.c8 FROM ft1, ft2 WHERE ft1.c1 = ft2.c1 AND ft1.c1 = 1; -- ERROR
25922592
ERROR: invalid input syntax for integer: "foo"
25932593
CONTEXT: column "c8" of foreign table "ft1"
2594+
SELECT ft1.c1, ft2.c2, ft1 FROM ft1, ft2 WHERE ft1.c1 = ft2.c1 AND ft1.c1 = 1; -- ERROR
2595+
ERROR: invalid input syntax for integer: "foo"
2596+
CONTEXT: whole-row reference to foreign table "ft1"
25942597
ALTER FOREIGN TABLE ft1 ALTER COLUMN c8 TYPE user_enum;
25952598
-- ===================================================================
25962599
-- subtransaction

contrib/postgres_fdw/postgres_fdw.c

+14-3
Original file line numberDiff line numberDiff line change
@@ -4528,6 +4528,7 @@ conversion_error_callback(void *arg)
45284528
{
45294529
const char *attname = NULL;
45304530
const char *relname = NULL;
4531+
bool is_wholerow = false;
45314532
ConversionLocation *errpos = (ConversionLocation *) arg;
45324533

45334534
if (errpos->rel)
@@ -4560,12 +4561,22 @@ conversion_error_callback(void *arg)
45604561
Assert(IsA(var, Var));
45614562

45624563
rte = rt_fetch(var->varno, estate->es_range_table);
4564+
4565+
if (var->varattno == 0)
4566+
is_wholerow = true;
4567+
else
4568+
attname = get_relid_attribute_name(rte->relid, var->varattno);
4569+
45634570
relname = get_rel_name(rte->relid);
4564-
attname = get_relid_attribute_name(rte->relid, var->varattno);
45654571
}
45664572

4567-
if (attname && relname)
4568-
errcontext("column \"%s\" of foreign table \"%s\"", attname, relname);
4573+
if (relname)
4574+
{
4575+
if (is_wholerow)
4576+
errcontext("whole-row reference to foreign table \"%s\"", relname);
4577+
else if (attname)
4578+
errcontext("column \"%s\" of foreign table \"%s\"", attname, relname);
4579+
}
45694580
}
45704581

45714582
/*

contrib/postgres_fdw/sql/postgres_fdw.sql

+1
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ DROP FUNCTION f_test(int);
627627
ALTER FOREIGN TABLE ft1 ALTER COLUMN c8 TYPE int;
628628
SELECT * FROM ft1 WHERE c1 = 1; -- ERROR
629629
SELECT ft1.c1, ft2.c2, ft1.c8 FROM ft1, ft2 WHERE ft1.c1 = ft2.c1 AND ft1.c1 = 1; -- ERROR
630+
SELECT ft1.c1, ft2.c2, ft1 FROM ft1, ft2 WHERE ft1.c1 = ft2.c1 AND ft1.c1 = 1; -- ERROR
630631
ALTER FOREIGN TABLE ft1 ALTER COLUMN c8 TYPE user_enum;
631632

632633
-- ===================================================================

0 commit comments

Comments
 (0)