Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5c7f1fb

Browse files
author
Nikita Glukhov
committed
Add invisible internal coercion form
1 parent c6731a9 commit 5c7f1fb

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
@@ -2439,7 +2439,8 @@ deparseFuncExpr(FuncExpr *node, deparse_expr_cxt *context)
24392439
* If the function call came from an implicit coercion, then just show the
24402440
* first argument.
24412441
*/
2442-
if (node->funcformat == COERCE_IMPLICIT_CAST)
2442+
if (node->funcformat == COERCE_IMPLICIT_CAST ||
2443+
node->funcformat == COERCE_INTERNAL_CAST)
24432444
{
24442445
deparseExpr((Expr *) linitial(node->args), context);
24452446
return;
@@ -2636,7 +2637,8 @@ static void
26362637
deparseRelabelType(RelabelType *node, deparse_expr_cxt *context)
26372638
{
26382639
deparseExpr(node->arg, context);
2639-
if (node->relabelformat != COERCE_IMPLICIT_CAST)
2640+
if (node->relabelformat != COERCE_IMPLICIT_CAST &&
2641+
node->relabelformat == COERCE_INTERNAL_CAST)
26402642
appendStringInfo(context->buf, "::%s",
26412643
deparse_type_name(node->resulttype,
26422644
node->resulttypmod));

src/backend/utils/adt/ruleutils.c

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

74167416
if (type == COERCE_EXPLICIT_CAST ||
7417-
type == COERCE_IMPLICIT_CAST)
7417+
type == COERCE_IMPLICIT_CAST ||
7418+
type == COERCE_INTERNAL_CAST)
74187419
return false;
7420+
74197421
return true; /* own parentheses */
74207422
}
74217423
case T_BoolExpr: /* lower precedence */
@@ -7465,7 +7467,8 @@ isSimpleNode(Node *node, Node *parentNode, int prettyFlags)
74657467
CoercionForm type = ((FuncExpr *) parentNode)->funcformat;
74667468

74677469
if (type == COERCE_EXPLICIT_CAST ||
7468-
type == COERCE_IMPLICIT_CAST)
7470+
type == COERCE_IMPLICIT_CAST ||
7471+
type == COERCE_INTERNAL_CAST)
74697472
return false;
74707473
return true; /* own parentheses */
74717474
}
@@ -7590,6 +7593,25 @@ get_rule_expr_paren(Node *node, deparse_context *context,
75907593
}
75917594

75927595

7596+
/*
7597+
* get_coercion - Parse back a coercion
7598+
*/
7599+
static void
7600+
get_coercion(Expr *arg, deparse_context *context, bool showimplicit,
7601+
Node *node, CoercionForm format, Oid typid, int32 typmod)
7602+
{
7603+
if (format == COERCE_INTERNAL_CAST ||
7604+
(format == COERCE_IMPLICIT_CAST && !showimplicit))
7605+
{
7606+
/* don't show the implicit cast */
7607+
get_rule_expr_paren((Node *) arg, context, false, node);
7608+
}
7609+
else
7610+
{
7611+
get_coercion_expr((Node *) arg, context, typid, typmod, node);
7612+
}
7613+
}
7614+
75937615
/* ----------
75947616
* get_rule_expr - Parse back an expression
75957617
*
@@ -7970,83 +7992,38 @@ get_rule_expr(Node *node, deparse_context *context,
79707992
case T_RelabelType:
79717993
{
79727994
RelabelType *relabel = (RelabelType *) node;
7973-
Node *arg = (Node *) relabel->arg;
79747995

7975-
if (relabel->relabelformat == COERCE_IMPLICIT_CAST &&
7976-
!showimplicit)
7977-
{
7978-
/* don't show the implicit cast */
7979-
get_rule_expr_paren(arg, context, false, node);
7980-
}
7981-
else
7982-
{
7983-
get_coercion_expr(arg, context,
7984-
relabel->resulttype,
7985-
relabel->resulttypmod,
7986-
node);
7987-
}
7996+
get_coercion(relabel->arg, context, showimplicit, node,
7997+
relabel->relabelformat, relabel->resulttype,
7998+
relabel->resulttypmod);
79887999
}
79898000
break;
79908001

79918002
case T_CoerceViaIO:
79928003
{
79938004
CoerceViaIO *iocoerce = (CoerceViaIO *) node;
7994-
Node *arg = (Node *) iocoerce->arg;
79958005

7996-
if (iocoerce->coerceformat == COERCE_IMPLICIT_CAST &&
7997-
!showimplicit)
7998-
{
7999-
/* don't show the implicit cast */
8000-
get_rule_expr_paren(arg, context, false, node);
8001-
}
8002-
else
8003-
{
8004-
get_coercion_expr(arg, context,
8005-
iocoerce->resulttype,
8006-
-1,
8007-
node);
8008-
}
8006+
get_coercion(iocoerce->arg, context, showimplicit, node,
8007+
iocoerce->coerceformat, iocoerce->resulttype, -1);
80098008
}
80108009
break;
80118010

80128011
case T_ArrayCoerceExpr:
80138012
{
80148013
ArrayCoerceExpr *acoerce = (ArrayCoerceExpr *) node;
8015-
Node *arg = (Node *) acoerce->arg;
80168014

8017-
if (acoerce->coerceformat == COERCE_IMPLICIT_CAST &&
8018-
!showimplicit)
8019-
{
8020-
/* don't show the implicit cast */
8021-
get_rule_expr_paren(arg, context, false, node);
8022-
}
8023-
else
8024-
{
8025-
get_coercion_expr(arg, context,
8026-
acoerce->resulttype,
8027-
acoerce->resulttypmod,
8028-
node);
8029-
}
8015+
get_coercion(acoerce->arg, context, showimplicit, node,
8016+
acoerce->coerceformat, acoerce->resulttype,
8017+
acoerce->resulttypmod);
80308018
}
80318019
break;
80328020

80338021
case T_ConvertRowtypeExpr:
80348022
{
80358023
ConvertRowtypeExpr *convert = (ConvertRowtypeExpr *) node;
8036-
Node *arg = (Node *) convert->arg;
80378024

8038-
if (convert->convertformat == COERCE_IMPLICIT_CAST &&
8039-
!showimplicit)
8040-
{
8041-
/* don't show the implicit cast */
8042-
get_rule_expr_paren(arg, context, false, node);
8043-
}
8044-
else
8045-
{
8046-
get_coercion_expr(arg, context,
8047-
convert->resulttype, -1,
8048-
node);
8049-
}
8025+
get_coercion(convert->arg, context, showimplicit, node,
8026+
convert->convertformat, convert->resulttype, -1);
80508027
}
80518028
break;
80528029

@@ -8599,21 +8576,10 @@ get_rule_expr(Node *node, deparse_context *context,
85998576
case T_CoerceToDomain:
86008577
{
86018578
CoerceToDomain *ctest = (CoerceToDomain *) node;
8602-
Node *arg = (Node *) ctest->arg;
86038579

8604-
if (ctest->coercionformat == COERCE_IMPLICIT_CAST &&
8605-
!showimplicit)
8606-
{
8607-
/* don't show the implicit cast */
8608-
get_rule_expr(arg, context, false);
8609-
}
8610-
else
8611-
{
8612-
get_coercion_expr(arg, context,
8613-
ctest->resulttype,
8614-
ctest->resulttypmod,
8615-
node);
8616-
}
8580+
get_coercion(ctest->arg, context, showimplicit, node,
8581+
ctest->coercionformat, ctest->resulttype,
8582+
ctest->resulttypmod);
86178583
}
86188584
break;
86198585

@@ -8945,7 +8911,8 @@ get_func_expr(FuncExpr *expr, deparse_context *context,
89458911
* If the function call came from an implicit coercion, then just show the
89468912
* first argument --- unless caller wants to see implicit coercions.
89478913
*/
8948-
if (expr->funcformat == COERCE_IMPLICIT_CAST && !showimplicit)
8914+
if (expr->funcformat == COERCE_INTERNAL_CAST ||
8915+
(expr->funcformat == COERCE_IMPLICIT_CAST && !showimplicit))
89498916
{
89508917
get_rule_expr_paren((Node *) linitial(expr->args), context,
89518918
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)