Skip to content

Commit ec67b89

Browse files
committed
Add UtilityReturnsTuples() support for CALL
This ensures that prepared statements for CALL can return tuples.
1 parent cccf81d commit ec67b89

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

src/backend/commands/functioncmds.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "commands/proclang.h"
5252
#include "executor/execdesc.h"
5353
#include "executor/executor.h"
54+
#include "funcapi.h"
5455
#include "miscadmin.h"
5556
#include "optimizer/clauses.h"
5657
#include "optimizer/var.h"
@@ -2340,3 +2341,26 @@ ExecuteCallStmt(CallStmt *stmt, ParamListInfo params, bool atomic, DestReceiver
23402341

23412342
FreeExecutorState(estate);
23422343
}
2344+
2345+
/*
2346+
* Construct the tuple descriptor for a CALL statement return
2347+
*/
2348+
TupleDesc
2349+
CallStmtResultDesc(CallStmt *stmt)
2350+
{
2351+
FuncExpr *fexpr;
2352+
HeapTuple tuple;
2353+
TupleDesc tupdesc;
2354+
2355+
fexpr = stmt->funcexpr;
2356+
2357+
tuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(fexpr->funcid));
2358+
if (!HeapTupleIsValid(tuple))
2359+
elog(ERROR, "cache lookup failed for procedure %u", fexpr->funcid);
2360+
2361+
tupdesc = build_function_result_tupdesc_t(tuple);
2362+
2363+
ReleaseSysCache(tuple);
2364+
2365+
return tupdesc;
2366+
}

src/backend/tcop/utility.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,6 +1744,12 @@ UtilityReturnsTuples(Node *parsetree)
17441744
{
17451745
switch (nodeTag(parsetree))
17461746
{
1747+
case T_CallStmt:
1748+
{
1749+
CallStmt *stmt = (CallStmt *) parsetree;
1750+
1751+
return (stmt->funcexpr->funcresulttype == RECORDOID);
1752+
}
17471753
case T_FetchStmt:
17481754
{
17491755
FetchStmt *stmt = (FetchStmt *) parsetree;
@@ -1794,6 +1800,9 @@ UtilityTupleDescriptor(Node *parsetree)
17941800
{
17951801
switch (nodeTag(parsetree))
17961802
{
1803+
case T_CallStmt:
1804+
return CallStmtResultDesc((CallStmt *) parsetree);
1805+
17971806
case T_FetchStmt:
17981807
{
17991808
FetchStmt *stmt = (FetchStmt *) parsetree;

src/include/commands/defrem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ extern void IsThereFunctionInNamespace(const char *proname, int pronargs,
6464
oidvector *proargtypes, Oid nspOid);
6565
extern void ExecuteDoStmt(DoStmt *stmt, bool atomic);
6666
extern void ExecuteCallStmt(CallStmt *stmt, ParamListInfo params, bool atomic, DestReceiver *dest);
67+
extern TupleDesc CallStmtResultDesc(CallStmt *stmt);
6768
extern Oid get_cast_oid(Oid sourcetypeid, Oid targettypeid, bool missing_ok);
6869
extern Oid get_transform_oid(Oid type_id, Oid lang_id, bool missing_ok);
6970
extern void interpret_function_parameter_list(ParseState *pstate,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy