* get_view_query - get the Query from a view's _RETURN rule. * * Caller should have verified that the relation is a view, and therefore * we should find an ON SELECT action. * * Note that the pointer returned is into the relcache and therefore must * be treated as read-only to the caller and not modified or scribbled on. */
| 2505 | * be treated as read-only to the caller and not modified or scribbled on. |
| 2506 | */ |
| 2507 | Query * |
| 2508 | get_view_query(Relation view) |
| 2509 | { |
| 2510 | int i; |
| 2511 | |
| 2512 | Assert(view->rd_rel->relkind == RELKIND_VIEW); |
| 2513 | |
| 2514 | for (i = 0; i < view->rd_rules->numLocks; i++) |
| 2515 | { |
| 2516 | RewriteRule *rule = view->rd_rules->rules[i]; |
| 2517 | |
| 2518 | if (rule->event == CMD_SELECT) |
| 2519 | { |
| 2520 | /* A _RETURN rule should have only one action */ |
| 2521 | if (list_length(rule->actions) != 1) |
| 2522 | elog(ERROR, "invalid _RETURN rule action specification"); |
| 2523 | |
| 2524 | return (Query *) linitial(rule->actions); |
| 2525 | } |
| 2526 | } |
| 2527 | |
| 2528 | elog(ERROR, "failed to find _RETURN rule for view"); |
| 2529 | return NULL; /* keep compiler quiet */ |
| 2530 | } |
| 2531 | |
| 2532 | |
| 2533 | /* |
no test coverage detected