Commit 0fe931a3 authored by Tom Lane's avatar Tom Lane

Code review for anonymous-functions patch --- clean up some confusion

in checkretval about which paths are for base or complex return type.
parent 44582cd8
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.85 2002/08/04 23:49:59 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.86 2002/08/05 00:21:27 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -372,25 +372,27 @@ checkretval(Oid rettype, char fn_typtype, List *queryTreeList) ...@@ -372,25 +372,27 @@ checkretval(Oid rettype, char fn_typtype, List *queryTreeList)
if (fn_typtype == 'b') if (fn_typtype == 'b')
{ {
/* Shouldn't have a typerelid */
Assert(typerelid == InvalidOid);
/* /*
* For base-type returns, the target list should have exactly one * For base-type returns, the target list should have exactly one
* entry, and its type should agree with what the user declared. (As * entry, and its type should agree with what the user declared. (As
* of Postgres 7.2, we accept binary-compatible types too.) * of Postgres 7.2, we accept binary-compatible types too.)
*/ */
if (tlistlen != 1)
elog(ERROR, "function declared to return %s returns multiple columns in final SELECT",
format_type_be(rettype));
if (typerelid == InvalidOid) restype = ((TargetEntry *) lfirst(tlist))->resdom->restype;
{ if (!IsBinaryCompatible(restype, rettype))
if (tlistlen != 1) elog(ERROR, "return type mismatch in function: declared to return %s, returns %s",
elog(ERROR, "function declared to return %s returns multiple columns in final SELECT", format_type_be(rettype), format_type_be(restype));
format_type_be(rettype)); }
else if (fn_typtype == 'c')
restype = ((TargetEntry *) lfirst(tlist))->resdom->restype; {
if (!IsBinaryCompatible(restype, rettype)) /* Must have a typerelid */
elog(ERROR, "return type mismatch in function: declared to return %s, returns %s", Assert(typerelid != InvalidOid);
format_type_be(rettype), format_type_be(restype));
return;
}
/* /*
* If the target list is of length 1, and the type of the varnode in * If the target list is of length 1, and the type of the varnode in
...@@ -405,14 +407,13 @@ checkretval(Oid rettype, char fn_typtype, List *queryTreeList) ...@@ -405,14 +407,13 @@ checkretval(Oid rettype, char fn_typtype, List *queryTreeList)
if (IsBinaryCompatible(restype, rettype)) if (IsBinaryCompatible(restype, rettype))
return; return;
} }
}
else if (fn_typtype == 'c')
{
/* /*
* By here, the procedure returns a tuple or set of tuples. This part * Otherwise verify that the targetlist matches the return tuple type.
* of the typechecking is a hack. We look up the relation that is the * This part of the typechecking is a hack. We look up the relation
* declared return type, and scan the non-deleted attributes to ensure * that is the declared return type, and scan the non-deleted
* that they match the datatypes of the non-resjunk columns. * attributes to ensure that they match the datatypes of the
* non-resjunk columns.
*/ */
reln = heap_open(typerelid, AccessShareLock); reln = heap_open(typerelid, AccessShareLock);
relnatts = reln->rd_rel->relnatts; relnatts = reln->rd_rel->relnatts;
...@@ -462,16 +463,16 @@ checkretval(Oid rettype, char fn_typtype, List *queryTreeList) ...@@ -462,16 +463,16 @@ checkretval(Oid rettype, char fn_typtype, List *queryTreeList)
format_type_be(rettype), rellogcols); format_type_be(rettype), rellogcols);
heap_close(reln, AccessShareLock); heap_close(reln, AccessShareLock);
return;
} }
else if (fn_typtype == 'p' && rettype == RECORDOID) else if (fn_typtype == 'p' && rettype == RECORDOID)
{ {
/* Shouldn't have a typerelid */
Assert(typerelid == InvalidOid);
/* /*
* For RECORD return type, defer this check until we get the * For RECORD return type, defer this check until we get the
* first tuple. * first tuple.
*/ */
return;
} }
else else
elog(ERROR, "Unknown kind of return type specified for function"); elog(ERROR, "Unknown kind of return type specified for function");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment