* FetchStatementTargetList * Given a statement that returns tuples, extract the query targetlist. * Returns NIL if the statement doesn't have a determinable targetlist. * * This can be applied to a Query or a PlannedStmt. * That's more general than portals need, but plancache.c uses this too. * * Note: do not modify the result. * * XXX be careful to keep this in sync with UtilityReturns
| 459 | * XXX be careful to keep this in sync with UtilityReturnsTuples. |
| 460 | */ |
| 461 | List * |
| 462 | FetchStatementTargetList(Node *stmt) |
| 463 | { |
| 464 | if (stmt == NULL) |
| 465 | return NIL; |
| 466 | if (IsA(stmt, Query)) |
| 467 | { |
| 468 | Query *query = (Query *) stmt; |
| 469 | |
| 470 | if (query->commandType == CMD_UTILITY) |
| 471 | { |
| 472 | /* transfer attention to utility statement */ |
| 473 | stmt = query->utilityStmt; |
| 474 | } |
| 475 | else |
| 476 | { |
| 477 | if (query->commandType == CMD_SELECT && |
| 478 | query->parentStmtType == PARENTSTMTTYPE_NONE) |
| 479 | return query->targetList; |
| 480 | if (query->returningList) |
| 481 | return query->returningList; |
| 482 | return NIL; |
| 483 | } |
| 484 | } |
| 485 | if (IsA(stmt, PlannedStmt)) |
| 486 | { |
| 487 | PlannedStmt *pstmt = (PlannedStmt *) stmt; |
| 488 | |
| 489 | if (pstmt->commandType == CMD_UTILITY) |
| 490 | { |
| 491 | /* transfer attention to utility statement */ |
| 492 | stmt = pstmt->utilityStmt; |
| 493 | } |
| 494 | else |
| 495 | { |
| 496 | if (pstmt->commandType == CMD_SELECT && |
| 497 | pstmt->intoClause == NULL && |
| 498 | pstmt->copyIntoClause == NULL && |
| 499 | pstmt->refreshClause == NULL) |
| 500 | return pstmt->planTree->targetlist; |
| 501 | if (pstmt->hasReturning) |
| 502 | return pstmt->planTree->targetlist; |
| 503 | return NIL; |
| 504 | } |
| 505 | } |
| 506 | if (IsA(stmt, FetchStmt)) |
| 507 | { |
| 508 | FetchStmt *fstmt = (FetchStmt *) stmt; |
| 509 | Portal subportal; |
| 510 | |
| 511 | Assert(!fstmt->ismove); |
| 512 | subportal = GetPortalByName(fstmt->portalname); |
| 513 | Assert(PortalIsValid(subportal)); |
| 514 | return FetchPortalTargetList(subportal); |
| 515 | } |
| 516 | if (IsA(stmt, ExecuteStmt)) |
| 517 | { |
| 518 | ExecuteStmt *estmt = (ExecuteStmt *) stmt; |
no test coverage detected