33 *back to source text
44 *
55 * IDENTIFICATION
6- * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.181 2004/09/13 20:07:13 tgl Exp $
6+ * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.182 2004/10/07 20:36:52 tgl Exp $
77 *
88 * This software is copyrighted by Jan Wieck - Hamburg.
99 *
@@ -2351,15 +2351,7 @@ get_insert_query_def(Query *query, deparse_context *context)
23512351{
23522352appendContextKeyword (context ,"VALUES (" ,
23532353- PRETTYINDENT_STD ,PRETTYINDENT_STD ,2 );
2354- sep = "" ;
2355- foreach (l ,strippedexprs )
2356- {
2357- Node * expr = lfirst (l );
2358-
2359- appendStringInfo (buf ,sep );
2360- sep = ", " ;
2361- get_rule_expr (expr ,context , false);
2362- }
2354+ get_rule_expr ((Node * )strippedexprs ,context , false);
23632355appendStringInfoChar (buf ,')' );
23642356}
23652357else
@@ -2938,7 +2930,9 @@ get_rule_expr(Node *node, deparse_context *context,
29382930/*
29392931 * Each level of get_rule_expr must emit an indivisible term
29402932 * (parenthesized if necessary) to ensure result is reparsed into the
2941- * same expression tree.
2933+ * same expression tree. The only exception is that when the input
2934+ * is a List, we emit the component items comma-separated with no
2935+ * surrounding decoration; this is convenient for most callers.
29422936 *
29432937 * There might be some work left here to support additional node types.
29442938 */
@@ -3269,20 +3263,10 @@ get_rule_expr(Node *node, deparse_context *context,
32693263case T_ArrayExpr :
32703264{
32713265ArrayExpr * arrayexpr = (ArrayExpr * )node ;
3272- ListCell * element ;
3273- char * sep ;
32743266
32753267appendStringInfo (buf ,"ARRAY[" );
3276- sep = "" ;
3277- foreach (element ,arrayexpr -> elements )
3278- {
3279- Node * e = (Node * )lfirst (element );
3280-
3281- appendStringInfo (buf ,sep );
3282- get_rule_expr (e ,context , true);
3283- sep = ", " ;
3284- }
3285- appendStringInfo (buf ,"]" );
3268+ get_rule_expr ((Node * )arrayexpr -> elements ,context , true);
3269+ appendStringInfoChar (buf ,']' );
32863270}
32873271break ;
32883272
@@ -3348,40 +3332,20 @@ get_rule_expr(Node *node, deparse_context *context,
33483332case T_CoalesceExpr :
33493333{
33503334CoalesceExpr * coalesceexpr = (CoalesceExpr * )node ;
3351- ListCell * arg ;
3352- char * sep ;
33533335
33543336appendStringInfo (buf ,"COALESCE(" );
3355- sep = "" ;
3356- foreach (arg ,coalesceexpr -> args )
3357- {
3358- Node * e = (Node * )lfirst (arg );
3359-
3360- appendStringInfo (buf ,sep );
3361- get_rule_expr (e ,context , true);
3362- sep = ", " ;
3363- }
3364- appendStringInfo (buf ,")" );
3337+ get_rule_expr ((Node * )coalesceexpr -> args ,context , true);
3338+ appendStringInfoChar (buf ,')' );
33653339}
33663340break ;
33673341
33683342case T_NullIfExpr :
33693343{
33703344NullIfExpr * nullifexpr = (NullIfExpr * )node ;
3371- ListCell * arg ;
3372- char * sep ;
33733345
33743346appendStringInfo (buf ,"NULLIF(" );
3375- sep = "" ;
3376- foreach (arg ,nullifexpr -> args )
3377- {
3378- Node * e = (Node * )lfirst (arg );
3379-
3380- appendStringInfo (buf ,sep );
3381- get_rule_expr (e ,context , true);
3382- sep = ", " ;
3383- }
3384- appendStringInfo (buf ,")" );
3347+ get_rule_expr ((Node * )nullifexpr -> args ,context , true);
3348+ appendStringInfoChar (buf ,')' );
33853349}
33863350break ;
33873351
@@ -3478,6 +3442,21 @@ get_rule_expr(Node *node, deparse_context *context,
34783442appendStringInfo (buf ,"DEFAULT" );
34793443break ;
34803444
3445+ case T_List :
3446+ {
3447+ char * sep ;
3448+ ListCell * l ;
3449+
3450+ sep = "" ;
3451+ foreach (l , (List * )node )
3452+ {
3453+ appendStringInfo (buf ,sep );
3454+ get_rule_expr ((Node * )lfirst (l ),context ,showimplicit );
3455+ sep = ", " ;
3456+ }
3457+ }
3458+ break ;
3459+
34813460default :
34823461elog (ERROR ,"unrecognized node type: %d" , (int )nodeTag (node ));
34833462break ;
@@ -3560,7 +3539,6 @@ get_func_expr(FuncExpr *expr, deparse_context *context,
35603539Oid argtypes [FUNC_MAX_ARGS ];
35613540int nargs ;
35623541ListCell * l ;
3563- char * sep ;
35643542
35653543/*
35663544 * If the function call came from an implicit coercion, then just show
@@ -3613,14 +3591,7 @@ get_func_expr(FuncExpr *expr, deparse_context *context,
36133591
36143592appendStringInfo (buf ,"%s(" ,
36153593generate_function_name (funcoid ,nargs ,argtypes ));
3616-
3617- sep = "" ;
3618- foreach (l ,expr -> args )
3619- {
3620- appendStringInfo (buf ,sep );
3621- sep = ", " ;
3622- get_rule_expr ((Node * )lfirst (l ),context , true);
3623- }
3594+ get_rule_expr ((Node * )expr -> args ,context , true);
36243595appendStringInfoChar (buf ,')' );
36253596}
36263597
@@ -3787,8 +3758,6 @@ get_sublink_expr(SubLink *sublink, deparse_context *context)
37873758{
37883759StringInfo buf = context -> buf ;
37893760Query * query = (Query * ) (sublink -> subselect );
3790- ListCell * l ;
3791- char * sep ;
37923761bool need_paren ;
37933762
37943763if (sublink -> subLinkType == ARRAY_SUBLINK )
@@ -3801,19 +3770,10 @@ get_sublink_expr(SubLink *sublink, deparse_context *context)
38013770need_paren = (list_length (sublink -> lefthand )> 1 );
38023771if (need_paren )
38033772appendStringInfoChar (buf ,'(' );
3804-
3805- sep = "" ;
3806- foreach (l ,sublink -> lefthand )
3807- {
3808- appendStringInfo (buf ,sep );
3809- sep = ", " ;
3810- get_rule_expr ((Node * )lfirst (l ),context , true);
3811- }
3812-
3773+ get_rule_expr ((Node * )sublink -> lefthand ,context , true);
38133774if (need_paren )
3814- appendStringInfo (buf ,") " );
3815- else
3816- appendStringInfoChar (buf ,' ' );
3775+ appendStringInfoChar (buf ,')' );
3776+ appendStringInfoChar (buf ,' ' );
38173777}
38183778
38193779need_paren = true;