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

Commit 3896e63

Browse files
author
Nikita Glukhov
committed
Add function formats
1 parent 5c7f1fb commit 3896e63

File tree

10 files changed

+83
-6
lines changed

10 files changed

+83
-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
@@ -2480,11 +2480,13 @@ JumbleExpr(pgssJumbleState *jstate, Node *node)
24802480
Aggref *expr = (Aggref *) node;
24812481

24822482
APP_JUMB(expr->aggfnoid);
2483+
APP_JUMB(expr->aggformat);
24832484
JumbleExpr(jstate, (Node *) expr->aggdirectargs);
24842485
JumbleExpr(jstate, (Node *) expr->args);
24852486
JumbleExpr(jstate, (Node *) expr->aggorder);
24862487
JumbleExpr(jstate, (Node *) expr->aggdistinct);
24872488
JumbleExpr(jstate, (Node *) expr->aggfilter);
2489+
JumbleExpr(jstate, (Node *) expr->aggformatopts);
24882490
}
24892491
break;
24902492
case T_GroupingFunc:
@@ -2500,8 +2502,10 @@ JumbleExpr(pgssJumbleState *jstate, Node *node)
25002502

25012503
APP_JUMB(expr->winfnoid);
25022504
APP_JUMB(expr->winref);
2505+
APP_JUMB(expr->winformat);
25032506
JumbleExpr(jstate, (Node *) expr->args);
25042507
JumbleExpr(jstate, (Node *) expr->aggfilter);
2508+
JumbleExpr(jstate, (Node *) expr->winformatopts);
25052509
}
25062510
break;
25072511
case T_ArrayRef:
@@ -2519,7 +2523,9 @@ JumbleExpr(pgssJumbleState *jstate, Node *node)
25192523
FuncExpr *expr = (FuncExpr *) node;
25202524

25212525
APP_JUMB(expr->funcid);
2526+
APP_JUMB(expr->funcformat2);
25222527
JumbleExpr(jstate, (Node *) expr->args);
2528+
JumbleExpr(jstate, (Node *) expr->funcformatopts);
25232529
}
25242530
break;
25252531
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
@@ -1142,6 +1142,8 @@ _outAggref(StringInfo str, const Aggref *node)
11421142
WRITE_CHAR_FIELD(aggkind);
11431143
WRITE_UINT_FIELD(agglevelsup);
11441144
WRITE_ENUM_FIELD(aggsplit, AggSplit);
1145+
WRITE_ENUM_FIELD(aggformat, FuncFormat);
1146+
WRITE_NODE_FIELD(aggformatopts);
11451147
WRITE_LOCATION_FIELD(location);
11461148
}
11471149

@@ -1171,6 +1173,8 @@ _outWindowFunc(StringInfo str, const WindowFunc *node)
11711173
WRITE_UINT_FIELD(winref);
11721174
WRITE_BOOL_FIELD(winstar);
11731175
WRITE_BOOL_FIELD(winagg);
1176+
WRITE_ENUM_FIELD(winformat, FuncFormat);
1177+
WRITE_NODE_FIELD(winformatopts);
11741178
WRITE_LOCATION_FIELD(location);
11751179
}
11761180

@@ -1202,6 +1206,8 @@ _outFuncExpr(StringInfo str, const FuncExpr *node)
12021206
WRITE_OID_FIELD(funccollid);
12031207
WRITE_OID_FIELD(inputcollid);
12041208
WRITE_NODE_FIELD(args);
1209+
WRITE_ENUM_FIELD(funcformat2, FuncFormat);
1210+
WRITE_NODE_FIELD(funcformatopts);
12051211
WRITE_LOCATION_FIELD(location);
12061212
}
12071213

src/backend/nodes/readfuncs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,8 @@ _readAggref(void)
595595
READ_CHAR_FIELD(aggkind);
596596
READ_UINT_FIELD(agglevelsup);
597597
READ_ENUM_FIELD(aggsplit, AggSplit);
598+
READ_ENUM_FIELD(aggformat, FuncFormat);
599+
READ_NODE_FIELD(aggformatopts);
598600
READ_LOCATION_FIELD(location);
599601

600602
READ_DONE();
@@ -634,6 +636,8 @@ _readWindowFunc(void)
634636
READ_UINT_FIELD(winref);
635637
READ_BOOL_FIELD(winstar);
636638
READ_BOOL_FIELD(winagg);
639+
READ_ENUM_FIELD(winformat, FuncFormat);
640+
READ_NODE_FIELD(winformatopts);
637641
READ_LOCATION_FIELD(location);
638642

639643
READ_DONE();
@@ -675,6 +679,8 @@ _readFuncExpr(void)
675679
READ_OID_FIELD(funccollid);
676680
READ_OID_FIELD(inputcollid);
677681
READ_NODE_FIELD(args);
682+
READ_ENUM_FIELD(funcformat2, FuncFormat);
683+
READ_NODE_FIELD(funcformatopts);
678684
READ_LOCATION_FIELD(location);
679685

680686
READ_DONE();

src/backend/optimizer/util/clauses.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2586,6 +2586,8 @@ eval_const_expressions_mutator(Node *node,
25862586
newexpr->winref = expr->winref;
25872587
newexpr->winstar = expr->winstar;
25882588
newexpr->winagg = expr->winagg;
2589+
newexpr->winformat = expr->winformat;
2590+
newexpr->winformatopts = copyObject(expr->winformatopts);
25892591
newexpr->location = expr->location;
25902592

25912593
return (Node *) newexpr;
@@ -2632,6 +2634,8 @@ eval_const_expressions_mutator(Node *node,
26322634
newexpr->funccollid = expr->funccollid;
26332635
newexpr->inputcollid = expr->inputcollid;
26342636
newexpr->args = args;
2637+
newexpr->funcformat2 = expr->funcformat2;
2638+
newexpr->funcformatopts = copyObject(expr->funcformatopts);
26352639
newexpr->location = expr->location;
26362640
return (Node *) newexpr;
26372641
}

src/backend/utils/adt/ruleutils.c

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8892,6 +8892,16 @@ get_oper_expr(OpExpr *expr, deparse_context *context)
88928892
appendStringInfoChar(buf, ')');
88938893
}
88948894

8895+
static void
8896+
get_func_opts(FuncFormat aggformat, Node *aggformatopts, deparse_context *context)
8897+
{
8898+
switch (aggformat)
8899+
{
8900+
default:
8901+
break;
8902+
}
8903+
}
8904+
88958905
/*
88968906
* get_func_expr - Parse back a FuncExpr node
88978907
*/
@@ -8906,6 +8916,7 @@ get_func_expr(FuncExpr *expr, deparse_context *context,
89068916
List *argnames;
89078917
bool use_variadic;
89088918
ListCell *l;
8919+
const char *funcname;
89098920

89108921
/*
89118922
* If the function call came from an implicit coercion, then just show the
@@ -8960,12 +8971,19 @@ get_func_expr(FuncExpr *expr, deparse_context *context,
89608971
nargs++;
89618972
}
89628973

8963-
appendStringInfo(buf, "%s(",
8964-
generate_function_name(funcoid, nargs,
8965-
argnames, argtypes,
8966-
expr->funcvariadic,
8967-
&use_variadic,
8968-
context->special_exprkind));
8974+
switch (expr->funcformat2)
8975+
{
8976+
default:
8977+
funcname = generate_function_name(funcoid, nargs,
8978+
argnames, argtypes,
8979+
expr->funcvariadic,
8980+
&use_variadic,
8981+
context->special_exprkind);
8982+
break;
8983+
}
8984+
8985+
appendStringInfo(buf, "%s(", funcname);
8986+
89698987
nargs = 0;
89708988
foreach(l, expr->args)
89718989
{
@@ -8975,6 +8993,9 @@ get_func_expr(FuncExpr *expr, deparse_context *context,
89758993
appendStringInfoString(buf, "VARIADIC ");
89768994
get_rule_expr((Node *) lfirst(l), context, true);
89778995
}
8996+
8997+
get_func_opts(expr->funcformat2, expr->funcformatopts, context);
8998+
89788999
appendStringInfoChar(buf, ')');
89799000
}
89809001

@@ -9073,6 +9094,8 @@ get_agg_expr(Aggref *aggref, deparse_context *context,
90739094
}
90749095
}
90759096

9097+
get_func_opts(aggref->aggformat, aggref->aggformatopts, context);
9098+
90769099
if (aggref->aggfilter != NULL)
90779100
{
90789101
appendStringInfoString(buf, ") FILTER (WHERE ");
@@ -9139,6 +9162,8 @@ get_windowfunc_expr(WindowFunc *wfunc, deparse_context *context)
91399162
else
91409163
get_rule_expr((Node *) wfunc->args, context, true);
91419164

9165+
get_func_opts(wfunc->winformat, wfunc->winformatopts, context);
9166+
91429167
if (wfunc->aggfilter != NULL)
91439168
{
91449169
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

src/test/regress/expected/json_jsonpath.out

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,6 +1945,12 @@ select json '[1, 2, 3]' @* '{a: 2 + 3, "b": [$[*], 4, 5]}.*';
19451945
[1, 2, 3, 4, 5]
19461946
(2 rows)
19471947

1948+
select json '[1, 2, 3]' @* '{a: 2 + 3, "b": [$[*], 4, 5]}[*]';
1949+
?column?
1950+
--------------------------------
1951+
{"a": 5, "b": [1, 2, 3, 4, 5]}
1952+
(1 row)
1953+
19481954
select json '[1, 2, 3]' @* '{a: 2 + 3, "b": ($[*], 4, 5)}';
19491955
ERROR: Singleton SQL/JSON item required
19501956
select json '[1, 2, 3]' @* '{a: 2 + 3, "b": [$.map({x: @, y: @ < 3})[*], {z: "foo"}]}';

src/test/regress/sql/json_jsonpath.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ select json '[[1, 2], [3, 4, 5], [], [6, 7]]' @* '[$[*].map(@ + 10)[*] ? (@ > 13
421421
select json '[1, 2, 3]' @* '{}';
422422
select json '[1, 2, 3]' @* '{a: 2 + 3, "b": [$[*], 4, 5]}';
423423
select json '[1, 2, 3]' @* '{a: 2 + 3, "b": [$[*], 4, 5]}.*';
424+
select json '[1, 2, 3]' @* '{a: 2 + 3, "b": [$[*], 4, 5]}[*]';
424425
select json '[1, 2, 3]' @* '{a: 2 + 3, "b": ($[*], 4, 5)}';
425426
select json '[1, 2, 3]' @* '{a: 2 + 3, "b": [$.map({x: @, y: @ < 3})[*], {z: "foo"}]}';
426427

0 commit comments

Comments
 (0)