* Check that a proposed rowmark target relation is a legal target * * In most cases parser and/or planner should have noticed this already, but * they don't cover all cases. */
| 2303 | * they don't cover all cases. |
| 2304 | */ |
| 2305 | static void |
| 2306 | CheckValidRowMarkRel(Relation rel, RowMarkType markType) |
| 2307 | { |
| 2308 | FdwRoutine *fdwroutine; |
| 2309 | |
| 2310 | switch (rel->rd_rel->relkind) |
| 2311 | { |
| 2312 | case RELKIND_RELATION: |
| 2313 | case RELKIND_PARTITIONED_TABLE: |
| 2314 | /* OK */ |
| 2315 | break; |
| 2316 | case RELKIND_SEQUENCE: |
| 2317 | /* Must disallow this because we don't vacuum sequences */ |
| 2318 | ereport(ERROR, |
| 2319 | (errcode(ERRCODE_WRONG_OBJECT_TYPE), |
| 2320 | errmsg("cannot lock rows in sequence \"%s\"", |
| 2321 | RelationGetRelationName(rel)))); |
| 2322 | break; |
| 2323 | case RELKIND_TOASTVALUE: |
| 2324 | /* We could allow this, but there seems no good reason to */ |
| 2325 | ereport(ERROR, |
| 2326 | (errcode(ERRCODE_WRONG_OBJECT_TYPE), |
| 2327 | errmsg("cannot lock rows in TOAST relation \"%s\"", |
| 2328 | RelationGetRelationName(rel)))); |
| 2329 | break; |
| 2330 | case RELKIND_VIEW: |
| 2331 | /* Should not get here; planner should have expanded the view */ |
| 2332 | ereport(ERROR, |
| 2333 | (errcode(ERRCODE_WRONG_OBJECT_TYPE), |
| 2334 | errmsg("cannot lock rows in view \"%s\"", |
| 2335 | RelationGetRelationName(rel)))); |
| 2336 | break; |
| 2337 | case RELKIND_MATVIEW: |
| 2338 | /* Allow referencing a matview, but not actual locking clauses */ |
| 2339 | if (markType != ROW_MARK_REFERENCE) |
| 2340 | ereport(ERROR, |
| 2341 | (errcode(ERRCODE_WRONG_OBJECT_TYPE), |
| 2342 | errmsg("cannot lock rows in materialized view \"%s\"", |
| 2343 | RelationGetRelationName(rel)))); |
| 2344 | break; |
| 2345 | case RELKIND_FOREIGN_TABLE: |
| 2346 | /* Okay only if the FDW supports it */ |
| 2347 | fdwroutine = GetFdwRoutineForRelation(rel, false); |
| 2348 | if (fdwroutine->RefetchForeignRow == NULL) |
| 2349 | ereport(ERROR, |
| 2350 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 2351 | errmsg("cannot lock rows in foreign table \"%s\"", |
| 2352 | RelationGetRelationName(rel)))); |
| 2353 | break; |
| 2354 | case RELKIND_DIRECTORY_TABLE: |
| 2355 | /* Allow referencing a directory table, but not actual locking clauses */ |
| 2356 | if (markType != ROW_MARK_REFERENCE) |
| 2357 | ereport(ERROR, |
| 2358 | (errcode(ERRCODE_WRONG_OBJECT_TYPE), |
| 2359 | errmsg("cannot lock rows in directory table \"%s\"", |
| 2360 | RelationGetRelationName(rel)))); |
| 2361 | break; |
| 2362 | default: |
no test coverage detected