Skip to content

Commit 27ab1eb

Browse files
committed
Tweak parse location assignment for CURRENT_DATE and related constructs.
All these constructs generate parse trees consisting of a Const and a run-time type coercion (perhaps a FuncExpr or a CoerceViaIO). Modify the raw parse output so that we end up with the original token's location attached to the type coercion node while the Const has location -1; before, it was the other way around. This makes no difference in terms of what exprLocation() will say about the parse tree as a whole, so it should not have any user-visible impact. The point of changing it is that we do not want contrib/pg_stat_statements to treat these constructs as replaceable constants. It will do the right thing if the Const has location -1 rather than a valid location. This is a pretty ugly hack, but then this code is ugly already; we should someday replace this translation with special-purpose parse node(s) that would allow ruleutils.c to reconstruct the original query text. (See also commit 5d3fcc4, which also hacked location assignment rules for the benefit of pg_stat_statements.) Back-patch to 9.2 where pg_stat_statements grew the ability to recognize replaceable constants. Kyotaro Horiguchi
1 parent 1fe0659 commit 27ab1eb

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

src/backend/parser/gram.y

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10851,10 +10851,15 @@ func_expr: func_name '(' ')' over_clause
1085110851
* of type-input conversion functions. (As of PG 7.3
1085210852
* that is actually possible, but not clear that we want
1085310853
* to rely on it.)
10854+
*
10855+
* The token location is attached to the run-time
10856+
* typecast, not to the Const, for the convenience of
10857+
* pg_stat_statements (which doesn't want these constructs
10858+
* to appear to be replaceable constants).
1085410859
*/
1085510860
Node *n;
10856-
n = makeStringConstCast("now", @1, SystemTypeName("text"));
10857-
$$ = makeTypeCast(n, SystemTypeName("date"), -1);
10861+
n = makeStringConstCast("now", -1, SystemTypeName("text"));
10862+
$$ = makeTypeCast(n, SystemTypeName("date"), @1);
1085810863
}
1085910864
| CURRENT_TIME
1086010865
{
@@ -10863,8 +10868,8 @@ func_expr: func_name '(' ')' over_clause
1086310868
* See comments for CURRENT_DATE.
1086410869
*/
1086510870
Node *n;
10866-
n = makeStringConstCast("now", @1, SystemTypeName("text"));
10867-
$$ = makeTypeCast(n, SystemTypeName("timetz"), -1);
10871+
n = makeStringConstCast("now", -1, SystemTypeName("text"));
10872+
$$ = makeTypeCast(n, SystemTypeName("timetz"), @1);
1086810873
}
1086910874
| CURRENT_TIME '(' Iconst ')'
1087010875
{
@@ -10874,10 +10879,10 @@ func_expr: func_name '(' ')' over_clause
1087410879
*/
1087510880
Node *n;
1087610881
TypeName *d;
10877-
n = makeStringConstCast("now", @1, SystemTypeName("text"));
10882+
n = makeStringConstCast("now", -1, SystemTypeName("text"));
1087810883
d = SystemTypeName("timetz");
1087910884
d->typmods = list_make1(makeIntConst($3, @3));
10880-
$$ = makeTypeCast(n, d, -1);
10885+
$$ = makeTypeCast(n, d, @1);
1088110886
}
1088210887
| CURRENT_TIMESTAMP
1088310888
{
@@ -10904,10 +10909,10 @@ func_expr: func_name '(' ')' over_clause
1090410909
*/
1090510910
Node *n;
1090610911
TypeName *d;
10907-
n = makeStringConstCast("now", @1, SystemTypeName("text"));
10912+
n = makeStringConstCast("now", -1, SystemTypeName("text"));
1090810913
d = SystemTypeName("timestamptz");
1090910914
d->typmods = list_make1(makeIntConst($3, @3));
10910-
$$ = makeTypeCast(n, d, -1);
10915+
$$ = makeTypeCast(n, d, @1);
1091110916
}
1091210917
| LOCALTIME
1091310918
{
@@ -10916,8 +10921,8 @@ func_expr: func_name '(' ')' over_clause
1091610921
* See comments for CURRENT_DATE.
1091710922
*/
1091810923
Node *n;
10919-
n = makeStringConstCast("now", @1, SystemTypeName("text"));
10920-
$$ = makeTypeCast((Node *)n, SystemTypeName("time"), -1);
10924+
n = makeStringConstCast("now", -1, SystemTypeName("text"));
10925+
$$ = makeTypeCast((Node *)n, SystemTypeName("time"), @1);
1092110926
}
1092210927
| LOCALTIME '(' Iconst ')'
1092310928
{
@@ -10927,10 +10932,10 @@ func_expr: func_name '(' ')' over_clause
1092710932
*/
1092810933
Node *n;
1092910934
TypeName *d;
10930-
n = makeStringConstCast("now", @1, SystemTypeName("text"));
10935+
n = makeStringConstCast("now", -1, SystemTypeName("text"));
1093110936
d = SystemTypeName("time");
1093210937
d->typmods = list_make1(makeIntConst($3, @3));
10933-
$$ = makeTypeCast((Node *)n, d, -1);
10938+
$$ = makeTypeCast((Node *)n, d, @1);
1093410939
}
1093510940
| LOCALTIMESTAMP
1093610941
{
@@ -10939,8 +10944,8 @@ func_expr: func_name '(' ')' over_clause
1093910944
* See comments for CURRENT_DATE.
1094010945
*/
1094110946
Node *n;
10942-
n = makeStringConstCast("now", @1, SystemTypeName("text"));
10943-
$$ = makeTypeCast(n, SystemTypeName("timestamp"), -1);
10947+
n = makeStringConstCast("now", -1, SystemTypeName("text"));
10948+
$$ = makeTypeCast(n, SystemTypeName("timestamp"), @1);
1094410949
}
1094510950
| LOCALTIMESTAMP '(' Iconst ')'
1094610951
{
@@ -10950,10 +10955,10 @@ func_expr: func_name '(' ')' over_clause
1095010955
*/
1095110956
Node *n;
1095210957
TypeName *d;
10953-
n = makeStringConstCast("now", @1, SystemTypeName("text"));
10958+
n = makeStringConstCast("now", -1, SystemTypeName("text"));
1095410959
d = SystemTypeName("timestamp");
1095510960
d->typmods = list_make1(makeIntConst($3, @3));
10956-
$$ = makeTypeCast(n, d, -1);
10961+
$$ = makeTypeCast(n, d, @1);
1095710962
}
1095810963
| CURRENT_ROLE
1095910964
{

0 commit comments

Comments
 (0)