* Callback function which is called when error occurs during column value * conversion. Print names of column and relation. * * Note that this function mustn't do any catalog lookups, since we are in * an already-failed transaction. Fortunately, we can get the needed info * from the relation or the query's rangetable instead. */
| 7402 | * from the relation or the query's rangetable instead. |
| 7403 | */ |
| 7404 | static void |
| 7405 | conversion_error_callback(void *arg) |
| 7406 | { |
| 7407 | ConversionLocation *errpos = (ConversionLocation *) arg; |
| 7408 | Relation rel = errpos->rel; |
| 7409 | ForeignScanState *fsstate = errpos->fsstate; |
| 7410 | const char *attname = NULL; |
| 7411 | const char *relname = NULL; |
| 7412 | bool is_wholerow = false; |
| 7413 | |
| 7414 | /* |
| 7415 | * If we're in a scan node, always use aliases from the rangetable, for |
| 7416 | * consistency between the simple-relation and remote-join cases. Look at |
| 7417 | * the relation's tupdesc only if we're not in a scan node. |
| 7418 | */ |
| 7419 | if (fsstate) |
| 7420 | { |
| 7421 | /* ForeignScan case */ |
| 7422 | ForeignScan *fsplan = castNode(ForeignScan, fsstate->ss.ps.plan); |
| 7423 | int varno = 0; |
| 7424 | AttrNumber colno = 0; |
| 7425 | |
| 7426 | if (fsplan->scan.scanrelid > 0) |
| 7427 | { |
| 7428 | /* error occurred in a scan against a foreign table */ |
| 7429 | varno = fsplan->scan.scanrelid; |
| 7430 | colno = errpos->cur_attno; |
| 7431 | } |
| 7432 | else |
| 7433 | { |
| 7434 | /* error occurred in a scan against a foreign join */ |
| 7435 | TargetEntry *tle; |
| 7436 | |
| 7437 | tle = list_nth_node(TargetEntry, fsplan->fdw_scan_tlist, |
| 7438 | errpos->cur_attno - 1); |
| 7439 | |
| 7440 | /* |
| 7441 | * Target list can have Vars and expressions. For Vars, we can |
| 7442 | * get some information, however for expressions we can't. Thus |
| 7443 | * for expressions, just show generic context message. |
| 7444 | */ |
| 7445 | if (IsA(tle->expr, Var)) |
| 7446 | { |
| 7447 | Var *var = (Var *) tle->expr; |
| 7448 | |
| 7449 | varno = var->varno; |
| 7450 | colno = var->varattno; |
| 7451 | } |
| 7452 | } |
| 7453 | |
| 7454 | if (varno > 0) |
| 7455 | { |
| 7456 | EState *estate = fsstate->ss.ps.state; |
| 7457 | RangeTblEntry *rte = exec_rt_fetch(varno, estate); |
| 7458 | |
| 7459 | relname = rte->eref->aliasname; |
| 7460 | |
| 7461 | if (colno == 0) |
nothing calls this directly
no test coverage detected