9
9
*
10
10
*
11
11
* IDENTIFICATION
12
- * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.268 2008/01/01 19:45:52 momjian Exp $
12
+ * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.269 2008/01/06 01:03:16 tgl Exp $
13
13
*
14
14
*-------------------------------------------------------------------------
15
15
*/
@@ -175,7 +175,7 @@ static void get_coercion_expr(Node *arg, deparse_context *context,
175
175
Oid resulttype , int32 resulttypmod ,
176
176
Node * parentNode );
177
177
static void get_const_expr (Const * constval , deparse_context * context ,
178
- bool showtype );
178
+ int showtype );
179
179
static void get_sublink_expr (SubLink * sublink , deparse_context * context );
180
180
static void get_from_clause (Query * query , const char * prefix ,
181
181
deparse_context * context );
@@ -2258,15 +2258,20 @@ get_rule_sortgroupclause(SortClause *srt, List *tlist, bool force_colno,
2258
2258
expr = (Node * ) tle -> expr ;
2259
2259
2260
2260
/*
2261
- * Use column-number form if requested by caller or if expression is a
2262
- * constant --- a constant is ambiguous (and will be misinterpreted by
2263
- * findTargetlistEntry()) if we dump it explicitly.
2261
+ * Use column-number form if requested by caller. Otherwise, if
2262
+ * expression is a constant, force it to be dumped with an explicit
2263
+ * cast as decoration --- this is because a simple integer constant
2264
+ * is ambiguous (and will be misinterpreted by findTargetlistEntry())
2265
+ * if we dump it without any decoration. Otherwise, just dump the
2266
+ * expression normally.
2264
2267
*/
2265
- if (force_colno || ( expr && IsA ( expr , Const )) )
2268
+ if (force_colno )
2266
2269
{
2267
2270
Assert (!tle -> resjunk );
2268
2271
appendStringInfo (buf , "%d" , tle -> resno );
2269
2272
}
2273
+ else if (expr && IsA (expr , Const ))
2274
+ get_const_expr ((Const * ) expr , context , 1 );
2270
2275
else
2271
2276
get_rule_expr (expr , context , true);
2272
2277
@@ -3409,7 +3414,7 @@ get_rule_expr(Node *node, deparse_context *context,
3409
3414
break ;
3410
3415
3411
3416
case T_Const :
3412
- get_const_expr ((Const * ) node , context , true );
3417
+ get_const_expr ((Const * ) node , context , 0 );
3413
3418
break ;
3414
3419
3415
3420
case T_Param :
@@ -4388,7 +4393,7 @@ get_coercion_expr(Node *arg, deparse_context *context,
4388
4393
((Const * ) arg )-> consttypmod == -1 )
4389
4394
{
4390
4395
/* Show the constant without normal ::typename decoration */
4391
- get_const_expr ((Const * ) arg , context , false );
4396
+ get_const_expr ((Const * ) arg , context , -1 );
4392
4397
}
4393
4398
else
4394
4399
{
@@ -4407,13 +4412,13 @@ get_coercion_expr(Node *arg, deparse_context *context,
4407
4412
*
4408
4413
* Make a string representation of a Const
4409
4414
*
4410
- * Note: if showtype is false, the Const is the direct argument of a coercion
4411
- * operation with the same target type, and so we should suppress "::typename"
4412
- * to avoid redundant output .
4415
+ * showtype can be -1 to never show "::typename" decoration, or +1 to always
4416
+ * show it, or 0 to show it only if the constant wouldn't be assumed to be
4417
+ * the right type by default .
4413
4418
* ----------
4414
4419
*/
4415
4420
static void
4416
- get_const_expr (Const * constval , deparse_context * context , bool showtype )
4421
+ get_const_expr (Const * constval , deparse_context * context , int showtype )
4417
4422
{
4418
4423
StringInfo buf = context -> buf ;
4419
4424
Oid typoutput ;
@@ -4430,7 +4435,7 @@ get_const_expr(Const *constval, deparse_context *context, bool showtype)
4430
4435
* about type when reparsing.
4431
4436
*/
4432
4437
appendStringInfo (buf , "NULL" );
4433
- if (showtype )
4438
+ if (showtype >= 0 )
4434
4439
appendStringInfo (buf , "::%s" ,
4435
4440
format_type_with_typemod (constval -> consttype ,
4436
4441
constval -> consttypmod ));
@@ -4506,13 +4511,15 @@ get_const_expr(Const *constval, deparse_context *context, bool showtype)
4506
4511
4507
4512
pfree (extval );
4508
4513
4509
- if (! showtype )
4514
+ if (showtype < 0 )
4510
4515
return ;
4511
4516
4512
4517
/*
4513
- * Append ::typename unless the constant will be implicitly typed as the
4514
- * right type when it is read in. XXX this code has to be kept in sync
4515
- * with the behavior of the parser, especially make_const.
4518
+ * For showtype == 0, append ::typename unless the constant will be
4519
+ * implicitly typed as the right type when it is read in.
4520
+ *
4521
+ * XXX this code has to be kept in sync with the behavior of the parser,
4522
+ * especially make_const.
4516
4523
*/
4517
4524
switch (constval -> consttype )
4518
4525
{
@@ -4534,7 +4541,7 @@ get_const_expr(Const *constval, deparse_context *context, bool showtype)
4534
4541
needlabel = true;
4535
4542
break ;
4536
4543
}
4537
- if (needlabel )
4544
+ if (needlabel || showtype > 0 )
4538
4545
appendStringInfo (buf , "::%s" ,
4539
4546
format_type_with_typemod (constval -> consttype ,
4540
4547
constval -> consttypmod ));
0 commit comments