* Complain if a namespace item is currently disallowed as a LATERAL reference. * This enforces both SQL:2008's rather odd idea of what to do with a LATERAL * reference to the wrong side of an outer join, and our own prohibition on * referencing the target table of an UPDATE or DELETE as a lateral reference * in a FROM/USING clause. * * Note: the pstate should be the same query level the nsit
| 469 | * Convenience subroutine to avoid multiple copies of a rather ugly ereport. |
| 470 | */ |
| 471 | static void |
| 472 | check_lateral_ref_ok(ParseState *pstate, ParseNamespaceItem *nsitem, |
| 473 | int location) |
| 474 | { |
| 475 | if (nsitem->p_lateral_only && !nsitem->p_lateral_ok) |
| 476 | { |
| 477 | /* SQL:2008 demands this be an error, not an invisible item */ |
| 478 | RangeTblEntry *rte = nsitem->p_rte; |
| 479 | char *refname = nsitem->p_names->aliasname; |
| 480 | |
| 481 | ereport(ERROR, |
| 482 | (errcode(ERRCODE_INVALID_COLUMN_REFERENCE), |
| 483 | errmsg("invalid reference to FROM-clause entry for table \"%s\"", |
| 484 | refname), |
| 485 | (pstate->p_target_nsitem != NULL && |
| 486 | rte == pstate->p_target_nsitem->p_rte) ? |
| 487 | errhint("There is an entry for table \"%s\", but it cannot be referenced from this part of the query.", |
| 488 | refname) : |
| 489 | errdetail("The combining JOIN type must be INNER or LEFT for a LATERAL reference."), |
| 490 | parser_errposition(pstate, location))); |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | /* |
| 495 | * Given an RT index and nesting depth, find the corresponding |
no test coverage detected