@@ -93,15 +93,14 @@ typedef struct
93
93
CommonTableExpr * parent_cte ;
94
94
} transform_query_cxt ;
95
95
96
-
97
96
typedef struct
98
97
{
99
98
Index child_varno ;
99
+ Oid parent_relid ;
100
100
List * translated_vars ;
101
101
} adjust_appendrel_varnos_cxt ;
102
102
103
103
104
-
105
104
static bool pathman_transform_query_walker (Node * node , void * context );
106
105
107
106
static void disable_standard_inheritance (Query * parse , transform_query_cxt * context );
@@ -473,9 +472,9 @@ handle_modification_query(Query *parse, transform_query_cxt *context)
473
472
474
473
/* Translate varnos for this child */
475
474
aav_cxt .child_varno = result_rti ;
475
+ aav_cxt .parent_relid = parent ;
476
476
aav_cxt .translated_vars = translated_vars ;
477
- if (adjust_appendrel_varnos ((Node * ) parse , & aav_cxt ))
478
- return ; /* failed to perform rewrites */
477
+ adjust_appendrel_varnos ((Node * ) parse , & aav_cxt );
479
478
480
479
/* Translate column privileges for this child */
481
480
rte -> selectedCols = translate_col_privs (rte -> selectedCols , translated_vars );
@@ -561,6 +560,7 @@ eval_extern_params_mutator(Node *node, ParamListInfo params)
561
560
(void * ) params );
562
561
}
563
562
563
+ /* Remap parent's attributes to child ones s*/
564
564
static bool
565
565
adjust_appendrel_varnos (Node * node , adjust_appendrel_varnos_cxt * context )
566
566
{
@@ -572,6 +572,7 @@ adjust_appendrel_varnos(Node *node, adjust_appendrel_varnos_cxt *context)
572
572
Query * query = (Query * ) node ;
573
573
ListCell * lc ;
574
574
575
+ /* FIXME: we might need to reorder TargetEntries */
575
576
foreach (lc , query -> targetList )
576
577
{
577
578
TargetEntry * te = (TargetEntry * ) lfirst (lc );
@@ -581,11 +582,13 @@ adjust_appendrel_varnos(Node *node, adjust_appendrel_varnos_cxt *context)
581
582
continue ;
582
583
583
584
if (te -> resno > list_length (context -> translated_vars ))
584
- return true;
585
+ elog (ERROR , "attribute %d of relation \"%s\" does not exist" ,
586
+ te -> resno , get_rel_name (context -> parent_relid ));
585
587
586
588
child_var = list_nth (context -> translated_vars , te -> resno - 1 );
587
589
if (!child_var )
588
- return true;
590
+ elog (ERROR , "attribute %d of relation \"%s\" does not exist" ,
591
+ te -> resno , get_rel_name (context -> parent_relid ));
589
592
590
593
/* Transform attribute number */
591
594
te -> resno = child_var -> varattno ;
@@ -601,17 +604,19 @@ adjust_appendrel_varnos(Node *node, adjust_appendrel_varnos_cxt *context)
601
604
{
602
605
Var * var = (Var * ) node ;
603
606
604
- /* Don't tranform system columns & other relations' Vars */
607
+ /* Don't transform system columns & other relations' Vars */
605
608
if (var -> varoattno > 0 && var -> varno == context -> child_varno )
606
609
{
607
610
Var * child_var ;
608
611
609
612
if (var -> varattno > list_length (context -> translated_vars ))
610
- return true;
613
+ elog (ERROR , "attribute %d of relation \"%s\" does not exist" ,
614
+ var -> varattno , get_rel_name (context -> parent_relid ));
611
615
612
616
child_var = list_nth (context -> translated_vars , var -> varattno - 1 );
613
617
if (!child_var )
614
- return true;
618
+ elog (ERROR , "attribute %d of relation \"%s\" does not exist" ,
619
+ var -> varattno , get_rel_name (context -> parent_relid ));
615
620
616
621
/* Transform attribute number */
617
622
var -> varattno = child_var -> varattno ;
0 commit comments