@@ -7567,8 +7567,10 @@ isSimpleNode(Node *node, Node *parentNode, int prettyFlags)
75677567 CoercionForm type = ((FuncExpr * ) parentNode )-> funcformat ;
75687568
75697569 if (type == COERCE_EXPLICIT_CAST ||
7570- type == COERCE_IMPLICIT_CAST )
7570+ type == COERCE_IMPLICIT_CAST ||
7571+ type == COERCE_INTERNAL_CAST )
75717572 return false;
7573+
75727574 return true; /* own parentheses */
75737575 }
75747576 case T_BoolExpr : /* lower precedence */
@@ -7618,7 +7620,8 @@ isSimpleNode(Node *node, Node *parentNode, int prettyFlags)
76187620 CoercionForm type = ((FuncExpr * ) parentNode )-> funcformat ;
76197621
76207622 if (type == COERCE_EXPLICIT_CAST ||
7621- type == COERCE_IMPLICIT_CAST )
7623+ type == COERCE_IMPLICIT_CAST ||
7624+ type == COERCE_INTERNAL_CAST )
76227625 return false;
76237626 return true; /* own parentheses */
76247627 }
@@ -7743,6 +7746,25 @@ get_rule_expr_paren(Node *node, deparse_context *context,
77437746}
77447747
77457748
7749+ /*
7750+ * get_coercion - Parse back a coercion
7751+ */
7752+ static void
7753+ get_coercion (Expr * arg , deparse_context * context , bool showimplicit ,
7754+ Node * node , CoercionForm format , Oid typid , int32 typmod )
7755+ {
7756+ if (format == COERCE_INTERNAL_CAST ||
7757+ (format == COERCE_IMPLICIT_CAST && !showimplicit ))
7758+ {
7759+ /* don't show the implicit cast */
7760+ get_rule_expr_paren ((Node * ) arg , context , false, node );
7761+ }
7762+ else
7763+ {
7764+ get_coercion_expr ((Node * ) arg , context , typid , typmod , node );
7765+ }
7766+ }
7767+
77467768/* ----------
77477769 * get_rule_expr - Parse back an expression
77487770 *
@@ -8123,83 +8145,38 @@ get_rule_expr(Node *node, deparse_context *context,
81238145 case T_RelabelType :
81248146 {
81258147 RelabelType * relabel = (RelabelType * ) node ;
8126- Node * arg = (Node * ) relabel -> arg ;
81278148
8128- if (relabel -> relabelformat == COERCE_IMPLICIT_CAST &&
8129- !showimplicit )
8130- {
8131- /* don't show the implicit cast */
8132- get_rule_expr_paren (arg , context , false, node );
8133- }
8134- else
8135- {
8136- get_coercion_expr (arg , context ,
8137- relabel -> resulttype ,
8138- relabel -> resulttypmod ,
8139- node );
8140- }
8149+ get_coercion (relabel -> arg , context , showimplicit , node ,
8150+ relabel -> relabelformat , relabel -> resulttype ,
8151+ relabel -> resulttypmod );
81418152 }
81428153 break ;
81438154
81448155 case T_CoerceViaIO :
81458156 {
81468157 CoerceViaIO * iocoerce = (CoerceViaIO * ) node ;
8147- Node * arg = (Node * ) iocoerce -> arg ;
81488158
8149- if (iocoerce -> coerceformat == COERCE_IMPLICIT_CAST &&
8150- !showimplicit )
8151- {
8152- /* don't show the implicit cast */
8153- get_rule_expr_paren (arg , context , false, node );
8154- }
8155- else
8156- {
8157- get_coercion_expr (arg , context ,
8158- iocoerce -> resulttype ,
8159- -1 ,
8160- node );
8161- }
8159+ get_coercion (iocoerce -> arg , context , showimplicit , node ,
8160+ iocoerce -> coerceformat , iocoerce -> resulttype , -1 );
81628161 }
81638162 break ;
81648163
81658164 case T_ArrayCoerceExpr :
81668165 {
81678166 ArrayCoerceExpr * acoerce = (ArrayCoerceExpr * ) node ;
8168- Node * arg = (Node * ) acoerce -> arg ;
81698167
8170- if (acoerce -> coerceformat == COERCE_IMPLICIT_CAST &&
8171- !showimplicit )
8172- {
8173- /* don't show the implicit cast */
8174- get_rule_expr_paren (arg , context , false, node );
8175- }
8176- else
8177- {
8178- get_coercion_expr (arg , context ,
8179- acoerce -> resulttype ,
8180- acoerce -> resulttypmod ,
8181- node );
8182- }
8168+ get_coercion (acoerce -> arg , context , showimplicit , node ,
8169+ acoerce -> coerceformat , acoerce -> resulttype ,
8170+ acoerce -> resulttypmod );
81838171 }
81848172 break ;
81858173
81868174 case T_ConvertRowtypeExpr :
81878175 {
81888176 ConvertRowtypeExpr * convert = (ConvertRowtypeExpr * ) node ;
8189- Node * arg = (Node * ) convert -> arg ;
81908177
8191- if (convert -> convertformat == COERCE_IMPLICIT_CAST &&
8192- !showimplicit )
8193- {
8194- /* don't show the implicit cast */
8195- get_rule_expr_paren (arg , context , false, node );
8196- }
8197- else
8198- {
8199- get_coercion_expr (arg , context ,
8200- convert -> resulttype , -1 ,
8201- node );
8202- }
8178+ get_coercion (convert -> arg , context , showimplicit , node ,
8179+ convert -> convertformat , convert -> resulttype , -1 );
82038180 }
82048181 break ;
82058182
@@ -8752,21 +8729,10 @@ get_rule_expr(Node *node, deparse_context *context,
87528729 case T_CoerceToDomain :
87538730 {
87548731 CoerceToDomain * ctest = (CoerceToDomain * ) node ;
8755- Node * arg = (Node * ) ctest -> arg ;
87568732
8757- if (ctest -> coercionformat == COERCE_IMPLICIT_CAST &&
8758- !showimplicit )
8759- {
8760- /* don't show the implicit cast */
8761- get_rule_expr (arg , context , false);
8762- }
8763- else
8764- {
8765- get_coercion_expr (arg , context ,
8766- ctest -> resulttype ,
8767- ctest -> resulttypmod ,
8768- node );
8769- }
8733+ get_coercion (ctest -> arg , context , showimplicit , node ,
8734+ ctest -> coercionformat , ctest -> resulttype ,
8735+ ctest -> resulttypmod );
87708736 }
87718737 break ;
87728738
@@ -9098,7 +9064,8 @@ get_func_expr(FuncExpr *expr, deparse_context *context,
90989064 * If the function call came from an implicit coercion, then just show the
90999065 * first argument --- unless caller wants to see implicit coercions.
91009066 */
9101- if (expr -> funcformat == COERCE_IMPLICIT_CAST && !showimplicit )
9067+ if (expr -> funcformat == COERCE_INTERNAL_CAST ||
9068+ (expr -> funcformat == COERCE_IMPLICIT_CAST && !showimplicit ))
91029069 {
91039070 get_rule_expr_paren ((Node * ) linitial (expr -> args ), context ,
91049071 false, (Node * ) expr );
0 commit comments