Skip to content

Commit f9767d4

Browse files
author
Nikita Glukhov
committed
Add invisible internal coercion form
1 parent 4d973f9 commit f9767d4

File tree

3 files changed

+45
-75
lines changed

3 files changed

+45
-75
lines changed

contrib/postgres_fdw/deparse.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,7 +2583,8 @@ deparseFuncExpr(FuncExpr *node, deparse_expr_cxt *context)
25832583
* If the function call came from an implicit coercion, then just show the
25842584
* first argument.
25852585
*/
2586-
if (node->funcformat == COERCE_IMPLICIT_CAST)
2586+
if (node->funcformat == COERCE_IMPLICIT_CAST ||
2587+
node->funcformat == COERCE_INTERNAL_CAST)
25872588
{
25882589
deparseExpr((Expr *) linitial(node->args), context);
25892590
return;
@@ -2780,7 +2781,8 @@ static void
27802781
deparseRelabelType(RelabelType *node, deparse_expr_cxt *context)
27812782
{
27822783
deparseExpr(node->arg, context);
2783-
if (node->relabelformat != COERCE_IMPLICIT_CAST)
2784+
if (node->relabelformat != COERCE_IMPLICIT_CAST &&
2785+
node->relabelformat == COERCE_INTERNAL_CAST)
27842786
appendStringInfo(context->buf, "::%s",
27852787
deparse_type_name(node->resulttype,
27862788
node->resulttypmod));

src/backend/utils/adt/ruleutils.c

Lines changed: 39 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -7496,8 +7496,10 @@ isSimpleNode(Node *node, Node *parentNode, int prettyFlags)
74967496
CoercionForm type = ((FuncExpr *) parentNode)->funcformat;
74977497

74987498
if (type == COERCE_EXPLICIT_CAST ||
7499-
type == COERCE_IMPLICIT_CAST)
7499+
type == COERCE_IMPLICIT_CAST ||
7500+
type == COERCE_INTERNAL_CAST)
75007501
return false;
7502+
75017503
return true; /* own parentheses */
75027504
}
75037505
case T_BoolExpr: /* lower precedence */
@@ -7547,7 +7549,8 @@ isSimpleNode(Node *node, Node *parentNode, int prettyFlags)
75477549
CoercionForm type = ((FuncExpr *) parentNode)->funcformat;
75487550

75497551
if (type == COERCE_EXPLICIT_CAST ||
7550-
type == COERCE_IMPLICIT_CAST)
7552+
type == COERCE_IMPLICIT_CAST ||
7553+
type == COERCE_INTERNAL_CAST)
75517554
return false;
75527555
return true; /* own parentheses */
75537556
}
@@ -7672,6 +7675,25 @@ get_rule_expr_paren(Node *node, deparse_context *context,
76727675
}
76737676

76747677

7678+
/*
7679+
* get_coercion - Parse back a coercion
7680+
*/
7681+
static void
7682+
get_coercion(Expr *arg, deparse_context *context, bool showimplicit,
7683+
Node *node, CoercionForm format, Oid typid, int32 typmod)
7684+
{
7685+
if (format == COERCE_INTERNAL_CAST ||
7686+
(format == COERCE_IMPLICIT_CAST && !showimplicit))
7687+
{
7688+
/* don't show the implicit cast */
7689+
get_rule_expr_paren((Node *) arg, context, false, node);
7690+
}
7691+
else
7692+
{
7693+
get_coercion_expr((Node *) arg, context, typid, typmod, node);
7694+
}
7695+
}
7696+
76757697
/* ----------
76767698
* get_rule_expr - Parse back an expression
76777699
*
@@ -8052,83 +8074,38 @@ get_rule_expr(Node *node, deparse_context *context,
80528074
case T_RelabelType:
80538075
{
80548076
RelabelType *relabel = (RelabelType *) node;
8055-
Node *arg = (Node *) relabel->arg;
80568077

8057-
if (relabel->relabelformat == COERCE_IMPLICIT_CAST &&
8058-
!showimplicit)
8059-
{
8060-
/* don't show the implicit cast */
8061-
get_rule_expr_paren(arg, context, false, node);
8062-
}
8063-
else
8064-
{
8065-
get_coercion_expr(arg, context,
8066-
relabel->resulttype,
8067-
relabel->resulttypmod,
8068-
node);
8069-
}
8078+
get_coercion(relabel->arg, context, showimplicit, node,
8079+
relabel->relabelformat, relabel->resulttype,
8080+
relabel->resulttypmod);
80708081
}
80718082
break;
80728083

80738084
case T_CoerceViaIO:
80748085
{
80758086
CoerceViaIO *iocoerce = (CoerceViaIO *) node;
8076-
Node *arg = (Node *) iocoerce->arg;
80778087

8078-
if (iocoerce->coerceformat == COERCE_IMPLICIT_CAST &&
8079-
!showimplicit)
8080-
{
8081-
/* don't show the implicit cast */
8082-
get_rule_expr_paren(arg, context, false, node);
8083-
}
8084-
else
8085-
{
8086-
get_coercion_expr(arg, context,
8087-
iocoerce->resulttype,
8088-
-1,
8089-
node);
8090-
}
8088+
get_coercion(iocoerce->arg, context, showimplicit, node,
8089+
iocoerce->coerceformat, iocoerce->resulttype, -1);
80918090
}
80928091
break;
80938092

80948093
case T_ArrayCoerceExpr:
80958094
{
80968095
ArrayCoerceExpr *acoerce = (ArrayCoerceExpr *) node;
8097-
Node *arg = (Node *) acoerce->arg;
80988096

8099-
if (acoerce->coerceformat == COERCE_IMPLICIT_CAST &&
8100-
!showimplicit)
8101-
{
8102-
/* don't show the implicit cast */
8103-
get_rule_expr_paren(arg, context, false, node);
8104-
}
8105-
else
8106-
{
8107-
get_coercion_expr(arg, context,
8108-
acoerce->resulttype,
8109-
acoerce->resulttypmod,
8110-
node);
8111-
}
8097+
get_coercion(acoerce->arg, context, showimplicit, node,
8098+
acoerce->coerceformat, acoerce->resulttype,
8099+
acoerce->resulttypmod);
81128100
}
81138101
break;
81148102

81158103
case T_ConvertRowtypeExpr:
81168104
{
81178105
ConvertRowtypeExpr *convert = (ConvertRowtypeExpr *) node;
8118-
Node *arg = (Node *) convert->arg;
81198106

8120-
if (convert->convertformat == COERCE_IMPLICIT_CAST &&
8121-
!showimplicit)
8122-
{
8123-
/* don't show the implicit cast */
8124-
get_rule_expr_paren(arg, context, false, node);
8125-
}
8126-
else
8127-
{
8128-
get_coercion_expr(arg, context,
8129-
convert->resulttype, -1,
8130-
node);
8131-
}
8107+
get_coercion(convert->arg, context, showimplicit, node,
8108+
convert->convertformat, convert->resulttype, -1);
81328109
}
81338110
break;
81348111

@@ -8681,21 +8658,10 @@ get_rule_expr(Node *node, deparse_context *context,
86818658
case T_CoerceToDomain:
86828659
{
86838660
CoerceToDomain *ctest = (CoerceToDomain *) node;
8684-
Node *arg = (Node *) ctest->arg;
86858661

8686-
if (ctest->coercionformat == COERCE_IMPLICIT_CAST &&
8687-
!showimplicit)
8688-
{
8689-
/* don't show the implicit cast */
8690-
get_rule_expr(arg, context, false);
8691-
}
8692-
else
8693-
{
8694-
get_coercion_expr(arg, context,
8695-
ctest->resulttype,
8696-
ctest->resulttypmod,
8697-
node);
8698-
}
8662+
get_coercion(ctest->arg, context, showimplicit, node,
8663+
ctest->coercionformat, ctest->resulttype,
8664+
ctest->resulttypmod);
86998665
}
87008666
break;
87018667

@@ -9027,7 +8993,8 @@ get_func_expr(FuncExpr *expr, deparse_context *context,
90278993
* If the function call came from an implicit coercion, then just show the
90288994
* first argument --- unless caller wants to see implicit coercions.
90298995
*/
9030-
if (expr->funcformat == COERCE_IMPLICIT_CAST && !showimplicit)
8996+
if (expr->funcformat == COERCE_INTERNAL_CAST ||
8997+
(expr->funcformat == COERCE_IMPLICIT_CAST && !showimplicit))
90318998
{
90328999
get_rule_expr_paren((Node *) linitial(expr->args), context,
90339000
false, (Node *) expr);

src/include/nodes/primnodes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,8 @@ typedef enum CoercionForm
437437
{
438438
COERCE_EXPLICIT_CALL, /* display as a function call */
439439
COERCE_EXPLICIT_CAST, /* display as an explicit cast */
440-
COERCE_IMPLICIT_CAST /* implicit cast, so hide it */
440+
COERCE_IMPLICIT_CAST, /* implicit cast, so hide it */
441+
COERCE_INTERNAL_CAST /* internal cast, so hide it always */
441442
} CoercionForm;
442443

443444
/*

0 commit comments

Comments
 (0)