@@ -7405,8 +7405,10 @@ isSimpleNode(Node *node, Node *parentNode, int prettyFlags)
74057405 CoercionForm type = ((FuncExpr * ) parentNode )-> funcformat ;
74067406
74077407 if (type == COERCE_EXPLICIT_CAST ||
7408- type == COERCE_IMPLICIT_CAST )
7408+ type == COERCE_IMPLICIT_CAST ||
7409+ type == COERCE_INTERNAL_CAST )
74097410 return false;
7411+
74107412 return true; /* own parentheses */
74117413 }
74127414 case T_BoolExpr : /* lower precedence */
@@ -7456,7 +7458,8 @@ isSimpleNode(Node *node, Node *parentNode, int prettyFlags)
74567458 CoercionForm type = ((FuncExpr * ) parentNode )-> funcformat ;
74577459
74587460 if (type == COERCE_EXPLICIT_CAST ||
7459- type == COERCE_IMPLICIT_CAST )
7461+ type == COERCE_IMPLICIT_CAST ||
7462+ type == COERCE_INTERNAL_CAST )
74607463 return false;
74617464 return true; /* own parentheses */
74627465 }
@@ -7581,6 +7584,25 @@ get_rule_expr_paren(Node *node, deparse_context *context,
75817584}
75827585
75837586
7587+ /*
7588+ * get_coercion - Parse back a coercion
7589+ */
7590+ static void
7591+ get_coercion (Expr * arg , deparse_context * context , bool showimplicit ,
7592+ Node * node , CoercionForm format , Oid typid , int32 typmod )
7593+ {
7594+ if (format == COERCE_INTERNAL_CAST ||
7595+ (format == COERCE_IMPLICIT_CAST && !showimplicit ))
7596+ {
7597+ /* don't show the implicit cast */
7598+ get_rule_expr_paren ((Node * ) arg , context , false, node );
7599+ }
7600+ else
7601+ {
7602+ get_coercion_expr ((Node * ) arg , context , typid , typmod , node );
7603+ }
7604+ }
7605+
75847606/* ----------
75857607 * get_rule_expr - Parse back an expression
75867608 *
@@ -7961,83 +7983,38 @@ get_rule_expr(Node *node, deparse_context *context,
79617983 case T_RelabelType :
79627984 {
79637985 RelabelType * relabel = (RelabelType * ) node ;
7964- Node * arg = (Node * ) relabel -> arg ;
79657986
7966- if (relabel -> relabelformat == COERCE_IMPLICIT_CAST &&
7967- !showimplicit )
7968- {
7969- /* don't show the implicit cast */
7970- get_rule_expr_paren (arg , context , false, node );
7971- }
7972- else
7973- {
7974- get_coercion_expr (arg , context ,
7975- relabel -> resulttype ,
7976- relabel -> resulttypmod ,
7977- node );
7978- }
7987+ get_coercion (relabel -> arg , context , showimplicit , node ,
7988+ relabel -> relabelformat , relabel -> resulttype ,
7989+ relabel -> resulttypmod );
79797990 }
79807991 break ;
79817992
79827993 case T_CoerceViaIO :
79837994 {
79847995 CoerceViaIO * iocoerce = (CoerceViaIO * ) node ;
7985- Node * arg = (Node * ) iocoerce -> arg ;
79867996
7987- if (iocoerce -> coerceformat == COERCE_IMPLICIT_CAST &&
7988- !showimplicit )
7989- {
7990- /* don't show the implicit cast */
7991- get_rule_expr_paren (arg , context , false, node );
7992- }
7993- else
7994- {
7995- get_coercion_expr (arg , context ,
7996- iocoerce -> resulttype ,
7997- -1 ,
7998- node );
7999- }
7997+ get_coercion (iocoerce -> arg , context , showimplicit , node ,
7998+ iocoerce -> coerceformat , iocoerce -> resulttype , -1 );
80007999 }
80018000 break ;
80028001
80038002 case T_ArrayCoerceExpr :
80048003 {
80058004 ArrayCoerceExpr * acoerce = (ArrayCoerceExpr * ) node ;
8006- Node * arg = (Node * ) acoerce -> arg ;
80078005
8008- if (acoerce -> coerceformat == COERCE_IMPLICIT_CAST &&
8009- !showimplicit )
8010- {
8011- /* don't show the implicit cast */
8012- get_rule_expr_paren (arg , context , false, node );
8013- }
8014- else
8015- {
8016- get_coercion_expr (arg , context ,
8017- acoerce -> resulttype ,
8018- acoerce -> resulttypmod ,
8019- node );
8020- }
8006+ get_coercion (acoerce -> arg , context , showimplicit , node ,
8007+ acoerce -> coerceformat , acoerce -> resulttype ,
8008+ acoerce -> resulttypmod );
80218009 }
80228010 break ;
80238011
80248012 case T_ConvertRowtypeExpr :
80258013 {
80268014 ConvertRowtypeExpr * convert = (ConvertRowtypeExpr * ) node ;
8027- Node * arg = (Node * ) convert -> arg ;
80288015
8029- if (convert -> convertformat == COERCE_IMPLICIT_CAST &&
8030- !showimplicit )
8031- {
8032- /* don't show the implicit cast */
8033- get_rule_expr_paren (arg , context , false, node );
8034- }
8035- else
8036- {
8037- get_coercion_expr (arg , context ,
8038- convert -> resulttype , -1 ,
8039- node );
8040- }
8016+ get_coercion (convert -> arg , context , showimplicit , node ,
8017+ convert -> convertformat , convert -> resulttype , -1 );
80418018 }
80428019 break ;
80438020
@@ -8590,21 +8567,10 @@ get_rule_expr(Node *node, deparse_context *context,
85908567 case T_CoerceToDomain :
85918568 {
85928569 CoerceToDomain * ctest = (CoerceToDomain * ) node ;
8593- Node * arg = (Node * ) ctest -> arg ;
85948570
8595- if (ctest -> coercionformat == COERCE_IMPLICIT_CAST &&
8596- !showimplicit )
8597- {
8598- /* don't show the implicit cast */
8599- get_rule_expr (arg , context , false);
8600- }
8601- else
8602- {
8603- get_coercion_expr (arg , context ,
8604- ctest -> resulttype ,
8605- ctest -> resulttypmod ,
8606- node );
8607- }
8571+ get_coercion (ctest -> arg , context , showimplicit , node ,
8572+ ctest -> coercionformat , ctest -> resulttype ,
8573+ ctest -> resulttypmod );
86088574 }
86098575 break ;
86108576
@@ -8921,7 +8887,8 @@ get_func_expr(FuncExpr *expr, deparse_context *context,
89218887 * If the function call came from an implicit coercion, then just show the
89228888 * first argument --- unless caller wants to see implicit coercions.
89238889 */
8924- if (expr -> funcformat == COERCE_IMPLICIT_CAST && !showimplicit )
8890+ if (expr -> funcformat == COERCE_INTERNAL_CAST ||
8891+ (expr -> funcformat == COERCE_IMPLICIT_CAST && !showimplicit ))
89258892 {
89268893 get_rule_expr_paren ((Node * ) linitial (expr -> args ), context ,
89278894 false, (Node * ) expr );
0 commit comments