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

Commit 1ecc347

Browse files
author
Nikita Glukhov
committed
Add function formats
1 parent 44c9ca7 commit 1ecc347

File tree

8 files changed

+76
-6
lines changed

8 files changed

+76
-6
lines changed

contrib/pg_stat_statements/pg_stat_statements.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2506,11 +2506,13 @@ JumbleExpr(pgssJumbleState *jstate, Node *node)
25062506
Aggref *expr = (Aggref *) node;
25072507

25082508
APP_JUMB(expr->aggfnoid);
2509+
APP_JUMB(expr->aggformat);
25092510
JumbleExpr(jstate, (Node *) expr->aggdirectargs);
25102511
JumbleExpr(jstate, (Node *) expr->args);
25112512
JumbleExpr(jstate, (Node *) expr->aggorder);
25122513
JumbleExpr(jstate, (Node *) expr->aggdistinct);
25132514
JumbleExpr(jstate, (Node *) expr->aggfilter);
2515+
JumbleExpr(jstate, (Node *) expr->aggformatopts);
25142516
}
25152517
break;
25162518
case T_GroupingFunc:
@@ -2526,8 +2528,10 @@ JumbleExpr(pgssJumbleState *jstate, Node *node)
25262528

25272529
APP_JUMB(expr->winfnoid);
25282530
APP_JUMB(expr->winref);
2531+
APP_JUMB(expr->winformat);
25292532
JumbleExpr(jstate, (Node *) expr->args);
25302533
JumbleExpr(jstate, (Node *) expr->aggfilter);
2534+
JumbleExpr(jstate, (Node *) expr->winformatopts);
25312535
}
25322536
break;
25332537
case T_ArrayRef:
@@ -2545,7 +2549,9 @@ JumbleExpr(pgssJumbleState *jstate, Node *node)
25452549
FuncExpr *expr = (FuncExpr *) node;
25462550

25472551
APP_JUMB(expr->funcid);
2552+
APP_JUMB(expr->funcformat2);
25482553
JumbleExpr(jstate, (Node *) expr->args);
2554+
JumbleExpr(jstate, (Node *) expr->funcformatopts);
25492555
}
25502556
break;
25512557
case T_NamedArgExpr:

src/backend/nodes/copyfuncs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,8 @@ _copyAggref(const Aggref *from)
13681368
COPY_SCALAR_FIELD(aggkind);
13691369
COPY_SCALAR_FIELD(agglevelsup);
13701370
COPY_SCALAR_FIELD(aggsplit);
1371+
COPY_SCALAR_FIELD(aggformat);
1372+
COPY_NODE_FIELD(aggformatopts);
13711373
COPY_LOCATION_FIELD(location);
13721374

13731375
return newnode;
@@ -1407,6 +1409,8 @@ _copyWindowFunc(const WindowFunc *from)
14071409
COPY_SCALAR_FIELD(winref);
14081410
COPY_SCALAR_FIELD(winstar);
14091411
COPY_SCALAR_FIELD(winagg);
1412+
COPY_SCALAR_FIELD(winformat);
1413+
COPY_NODE_FIELD(winformatopts);
14101414
COPY_LOCATION_FIELD(location);
14111415

14121416
return newnode;
@@ -1448,6 +1452,8 @@ _copyFuncExpr(const FuncExpr *from)
14481452
COPY_SCALAR_FIELD(funccollid);
14491453
COPY_SCALAR_FIELD(inputcollid);
14501454
COPY_NODE_FIELD(args);
1455+
COPY_SCALAR_FIELD(funcformat2);
1456+
COPY_NODE_FIELD(funcformatopts);
14511457
COPY_LOCATION_FIELD(location);
14521458

14531459
return newnode;

src/backend/nodes/equalfuncs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ _equalAggref(const Aggref *a, const Aggref *b)
226226
COMPARE_SCALAR_FIELD(aggkind);
227227
COMPARE_SCALAR_FIELD(agglevelsup);
228228
COMPARE_SCALAR_FIELD(aggsplit);
229+
COMPARE_SCALAR_FIELD(aggformat);
230+
COMPARE_NODE_FIELD(aggformatopts);
229231
COMPARE_LOCATION_FIELD(location);
230232

231233
return true;
@@ -258,6 +260,8 @@ _equalWindowFunc(const WindowFunc *a, const WindowFunc *b)
258260
COMPARE_SCALAR_FIELD(winref);
259261
COMPARE_SCALAR_FIELD(winstar);
260262
COMPARE_SCALAR_FIELD(winagg);
263+
COMPARE_SCALAR_FIELD(winformat);
264+
COMPARE_NODE_FIELD(winformatopts);
261265
COMPARE_LOCATION_FIELD(location);
262266

263267
return true;
@@ -289,6 +293,8 @@ _equalFuncExpr(const FuncExpr *a, const FuncExpr *b)
289293
COMPARE_SCALAR_FIELD(funccollid);
290294
COMPARE_SCALAR_FIELD(inputcollid);
291295
COMPARE_NODE_FIELD(args);
296+
COMPARE_SCALAR_FIELD(funcformat2);
297+
COMPARE_NODE_FIELD(funcformatopts);
292298
COMPARE_LOCATION_FIELD(location);
293299

294300
return true;

src/backend/nodes/outfuncs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,8 @@ _outAggref(StringInfo str, const Aggref *node)
11371137
WRITE_CHAR_FIELD(aggkind);
11381138
WRITE_UINT_FIELD(agglevelsup);
11391139
WRITE_ENUM_FIELD(aggsplit, AggSplit);
1140+
WRITE_ENUM_FIELD(aggformat, FuncFormat);
1141+
WRITE_NODE_FIELD(aggformatopts);
11401142
WRITE_LOCATION_FIELD(location);
11411143
}
11421144

@@ -1166,6 +1168,8 @@ _outWindowFunc(StringInfo str, const WindowFunc *node)
11661168
WRITE_UINT_FIELD(winref);
11671169
WRITE_BOOL_FIELD(winstar);
11681170
WRITE_BOOL_FIELD(winagg);
1171+
WRITE_ENUM_FIELD(winformat, FuncFormat);
1172+
WRITE_NODE_FIELD(winformatopts);
11691173
WRITE_LOCATION_FIELD(location);
11701174
}
11711175

@@ -1197,6 +1201,8 @@ _outFuncExpr(StringInfo str, const FuncExpr *node)
11971201
WRITE_OID_FIELD(funccollid);
11981202
WRITE_OID_FIELD(inputcollid);
11991203
WRITE_NODE_FIELD(args);
1204+
WRITE_ENUM_FIELD(funcformat2, FuncFormat);
1205+
WRITE_NODE_FIELD(funcformatopts);
12001206
WRITE_LOCATION_FIELD(location);
12011207
}
12021208

src/backend/nodes/readfuncs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,8 @@ _readAggref(void)
588588
READ_CHAR_FIELD(aggkind);
589589
READ_UINT_FIELD(agglevelsup);
590590
READ_ENUM_FIELD(aggsplit, AggSplit);
591+
READ_ENUM_FIELD(aggformat, FuncFormat);
592+
READ_NODE_FIELD(aggformatopts);
591593
READ_LOCATION_FIELD(location);
592594

593595
READ_DONE();
@@ -627,6 +629,8 @@ _readWindowFunc(void)
627629
READ_UINT_FIELD(winref);
628630
READ_BOOL_FIELD(winstar);
629631
READ_BOOL_FIELD(winagg);
632+
READ_ENUM_FIELD(winformat, FuncFormat);
633+
READ_NODE_FIELD(winformatopts);
630634
READ_LOCATION_FIELD(location);
631635

632636
READ_DONE();
@@ -668,6 +672,8 @@ _readFuncExpr(void)
668672
READ_OID_FIELD(funccollid);
669673
READ_OID_FIELD(inputcollid);
670674
READ_NODE_FIELD(args);
675+
READ_ENUM_FIELD(funcformat2, FuncFormat);
676+
READ_NODE_FIELD(funcformatopts);
671677
READ_LOCATION_FIELD(location);
672678

673679
READ_DONE();

src/backend/optimizer/util/clauses.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2574,6 +2574,8 @@ eval_const_expressions_mutator(Node *node,
25742574
newexpr->winref = expr->winref;
25752575
newexpr->winstar = expr->winstar;
25762576
newexpr->winagg = expr->winagg;
2577+
newexpr->winformat = expr->winformat;
2578+
newexpr->winformatopts = copyObject(expr->winformatopts);
25772579
newexpr->location = expr->location;
25782580

25792581
return (Node *) newexpr;
@@ -2620,6 +2622,8 @@ eval_const_expressions_mutator(Node *node,
26202622
newexpr->funccollid = expr->funccollid;
26212623
newexpr->inputcollid = expr->inputcollid;
26222624
newexpr->args = args;
2625+
newexpr->funcformat2 = expr->funcformat2;
2626+
newexpr->funcformatopts = copyObject(expr->funcformatopts);
26232627
newexpr->location = expr->location;
26242628
return (Node *) newexpr;
26252629
}

src/backend/utils/adt/ruleutils.c

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8868,6 +8868,16 @@ get_oper_expr(OpExpr *expr, deparse_context *context)
88688868
appendStringInfoChar(buf, ')');
88698869
}
88708870

8871+
static void
8872+
get_func_opts(FuncFormat aggformat, Node *aggformatopts, deparse_context *context)
8873+
{
8874+
switch (aggformat)
8875+
{
8876+
default:
8877+
break;
8878+
}
8879+
}
8880+
88718881
/*
88728882
* get_func_expr - Parse back a FuncExpr node
88738883
*/
@@ -8882,6 +8892,7 @@ get_func_expr(FuncExpr *expr, deparse_context *context,
88828892
List *argnames;
88838893
bool use_variadic;
88848894
ListCell *l;
8895+
const char *funcname;
88858896

88868897
/*
88878898
* If the function call came from an implicit coercion, then just show the
@@ -8936,12 +8947,19 @@ get_func_expr(FuncExpr *expr, deparse_context *context,
89368947
nargs++;
89378948
}
89388949

8939-
appendStringInfo(buf, "%s(",
8940-
generate_function_name(funcoid, nargs,
8941-
argnames, argtypes,
8942-
expr->funcvariadic,
8943-
&use_variadic,
8944-
context->special_exprkind));
8950+
switch (expr->funcformat2)
8951+
{
8952+
default:
8953+
funcname = generate_function_name(funcoid, nargs,
8954+
argnames, argtypes,
8955+
expr->funcvariadic,
8956+
&use_variadic,
8957+
context->special_exprkind);
8958+
break;
8959+
}
8960+
8961+
appendStringInfo(buf, "%s(", funcname);
8962+
89458963
nargs = 0;
89468964
foreach(l, expr->args)
89478965
{
@@ -8951,6 +8969,9 @@ get_func_expr(FuncExpr *expr, deparse_context *context,
89518969
appendStringInfoString(buf, "VARIADIC ");
89528970
get_rule_expr((Node *) lfirst(l), context, true);
89538971
}
8972+
8973+
get_func_opts(expr->funcformat2, expr->funcformatopts, context);
8974+
89548975
appendStringInfoChar(buf, ')');
89558976
}
89568977

@@ -9049,6 +9070,8 @@ get_agg_expr(Aggref *aggref, deparse_context *context,
90499070
}
90509071
}
90519072

9073+
get_func_opts(aggref->aggformat, aggref->aggformatopts, context);
9074+
90529075
if (aggref->aggfilter != NULL)
90539076
{
90549077
appendStringInfoString(buf, ") FILTER (WHERE ");
@@ -9115,6 +9138,8 @@ get_windowfunc_expr(WindowFunc *wfunc, deparse_context *context)
91159138
else
91169139
get_rule_expr((Node *) wfunc->args, context, true);
91179140

9141+
get_func_opts(wfunc->winformat, wfunc->winformatopts, context);
9142+
91189143
if (wfunc->aggfilter != NULL)
91199144
{
91209145
appendStringInfoString(buf, ") FILTER (WHERE ");

src/include/nodes/primnodes.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ typedef struct Param
249249
int location; /* token location, or -1 if unknown */
250250
} Param;
251251

252+
typedef enum FuncFormat
253+
{
254+
FUNCFMT_REGULAR = 0,
255+
} FuncFormat;
256+
252257
/*
253258
* Aggref
254259
*
@@ -308,6 +313,8 @@ typedef struct Aggref
308313
char aggkind; /* aggregate kind (see pg_aggregate.h) */
309314
Index agglevelsup; /* > 0 if agg belongs to outer query */
310315
AggSplit aggsplit; /* expected agg-splitting mode of parent Agg */
316+
FuncFormat aggformat; /* how to display this aggregate */
317+
Node *aggformatopts; /* display options, if any */
311318
int location; /* token location, or -1 if unknown */
312319
} Aggref;
313320

@@ -361,6 +368,8 @@ typedef struct WindowFunc
361368
Index winref; /* index of associated WindowClause */
362369
bool winstar; /* TRUE if argument list was really '*' */
363370
bool winagg; /* is function a simple aggregate? */
371+
FuncFormat winformat; /* how to display this window function */
372+
Node *winformatopts; /* display options, if any */
364373
int location; /* token location, or -1 if unknown */
365374
} WindowFunc;
366375

@@ -456,6 +465,8 @@ typedef struct FuncExpr
456465
Oid funccollid; /* OID of collation of result */
457466
Oid inputcollid; /* OID of collation that function should use */
458467
List *args; /* arguments to the function */
468+
FuncFormat funcformat2; /* how to display this function call */
469+
Node *funcformatopts; /* display options, if any */
459470
int location; /* token location, or -1 if unknown */
460471
} FuncExpr;
461472

0 commit comments

Comments
 (0)