diff options
Diffstat (limited to 'src/backend/nodes/nodeFuncs.c')
-rw-r--r-- | src/backend/nodes/nodeFuncs.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/backend/nodes/nodeFuncs.c b/src/backend/nodes/nodeFuncs.c index a896d763b8f..908f397d501 100644 --- a/src/backend/nodes/nodeFuncs.c +++ b/src/backend/nodes/nodeFuncs.c @@ -572,6 +572,65 @@ relabel_to_typmod(Node *expr, int32 typmod) } /* + * strip_implicit_coercions: remove implicit coercions at top level of tree + * + * This doesn't modify or copy the input expression tree, just return a + * pointer to a suitable place within it. + * + * Note: there isn't any useful thing we can do with a RowExpr here, so + * just return it unchanged, even if it's marked as an implicit coercion. + */ +Node * +strip_implicit_coercions(Node *node) +{ + if (node == NULL) + return NULL; + if (IsA(node, FuncExpr)) + { + FuncExpr *f = (FuncExpr *) node; + + if (f->funcformat == COERCE_IMPLICIT_CAST) + return strip_implicit_coercions(linitial(f->args)); + } + else if (IsA(node, RelabelType)) + { + RelabelType *r = (RelabelType *) node; + + if (r->relabelformat == COERCE_IMPLICIT_CAST) + return strip_implicit_coercions((Node *) r->arg); + } + else if (IsA(node, CoerceViaIO)) + { + CoerceViaIO *c = (CoerceViaIO *) node; + + if (c->coerceformat == COERCE_IMPLICIT_CAST) + return strip_implicit_coercions((Node *) c->arg); + } + else if (IsA(node, ArrayCoerceExpr)) + { + ArrayCoerceExpr *c = (ArrayCoerceExpr *) node; + + if (c->coerceformat == COERCE_IMPLICIT_CAST) + return strip_implicit_coercions((Node *) c->arg); + } + else if (IsA(node, ConvertRowtypeExpr)) + { + ConvertRowtypeExpr *c = (ConvertRowtypeExpr *) node; + + if (c->convertformat == COERCE_IMPLICIT_CAST) + return strip_implicit_coercions((Node *) c->arg); + } + else if (IsA(node, CoerceToDomain)) + { + CoerceToDomain *c = (CoerceToDomain *) node; + + if (c->coercionformat == COERCE_IMPLICIT_CAST) + return strip_implicit_coercions((Node *) c->arg); + } + return node; +} + +/* * expression_returns_set * Test whether an expression returns a set result. * |