summaryrefslogtreecommitdiff
path: root/src/backend/nodes/nodeFuncs.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2009-03-10 22:09:26 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2009-03-10 22:09:26 +0000
commitdcf3902f02db09a067f066bd46bc3ad354f323b9 (patch)
treea315476b4728f96646d4dfef5ce7edaad2e22f94 /src/backend/nodes/nodeFuncs.c
parent4886dc92e0a45e50600187e7ff8e289e14ded5ca (diff)
Make SubPlan nodes carry the result's typmod as well as datatype OID. This is
for consistency with the (relatively) recent addition of typmod to SubLink. An example of why it's a good idea is to be seen in the recent "failed to locate grouping columns" bug, which wouldn't have happened if a SubPlan exposed the same typmod info as the SubLink it was derived from. This could be back-patched, since it doesn't affect any on-disk data format, but for the moment it doesn't seem necessary to do so.
Diffstat (limited to 'src/backend/nodes/nodeFuncs.c')
-rw-r--r--src/backend/nodes/nodeFuncs.c40
1 files changed, 30 insertions, 10 deletions
diff --git a/src/backend/nodes/nodeFuncs.c b/src/backend/nodes/nodeFuncs.c
index 8a04d71eb82..d0a34347830 100644
--- a/src/backend/nodes/nodeFuncs.c
+++ b/src/backend/nodes/nodeFuncs.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/nodes/nodeFuncs.c,v 1.38 2009/02/25 03:30:37 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/nodes/nodeFuncs.c,v 1.39 2009/03/10 22:09:25 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -28,7 +28,7 @@ static int leftmostLoc(int loc1, int loc2);
/*
* exprType -
- * returns the Oid of the type of the expression. (Used for typechecking.)
+ * returns the Oid of the type of the expression's result.
*/
Oid
exprType(Node *expr)
@@ -117,11 +117,6 @@ exprType(Node *expr)
break;
case T_SubPlan:
{
- /*
- * Although the parser does not ever deal with already-planned
- * expression trees, we support SubPlan nodes in this routine
- * for the convenience of ruleutils.c.
- */
SubPlan *subplan = (SubPlan *) expr;
if (subplan->subLinkType == EXPR_SUBLINK ||
@@ -148,7 +143,6 @@ exprType(Node *expr)
break;
case T_AlternativeSubPlan:
{
- /* As above, supported for the convenience of ruleutils.c */
AlternativeSubPlan *asplan = (AlternativeSubPlan *) expr;
/* subplans should all return the same thing */
@@ -236,8 +230,8 @@ exprType(Node *expr)
/*
* exprTypmod -
- * returns the type-specific attrmod of the expression, if it can be
- * determined. In most cases, it can't and we return -1.
+ * returns the type-specific modifier of the expression's result type,
+ * if it can be determined. In many cases, it can't and we return -1.
*/
int32
exprTypmod(Node *expr)
@@ -286,6 +280,32 @@ exprTypmod(Node *expr)
}
}
break;
+ case T_SubPlan:
+ {
+ SubPlan *subplan = (SubPlan *) expr;
+
+ if (subplan->subLinkType == EXPR_SUBLINK ||
+ subplan->subLinkType == ARRAY_SUBLINK)
+ {
+ /* get the typmod of the subselect's first target column */
+ /* note we don't need to care if it's an array */
+ return subplan->firstColTypmod;
+ }
+ else
+ {
+ /* for all other subplan types, result is boolean */
+ return -1;
+ }
+ }
+ break;
+ case T_AlternativeSubPlan:
+ {
+ AlternativeSubPlan *asplan = (AlternativeSubPlan *) expr;
+
+ /* subplans should all return the same thing */
+ return exprTypmod((Node *) linitial(asplan->subplans));
+ }
+ break;
case T_FieldSelect:
return ((FieldSelect *) expr)->resulttypmod;
case T_RelabelType: