mirror of
https://github.com/postgres/postgres.git
synced 2025-04-22 23:02:54 +03:00
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 5d3fcc4c2e137417ef470d604fee5e452b22f6a7, 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
This commit is contained in:
parent
3888b73f9a
commit
0950d67ee5
@ -11234,10 +11234,15 @@ func_expr: func_name '(' ')' over_clause
|
|||||||
* of type-input conversion functions. (As of PG 7.3
|
* of type-input conversion functions. (As of PG 7.3
|
||||||
* that is actually possible, but not clear that we want
|
* that is actually possible, but not clear that we want
|
||||||
* to rely on it.)
|
* to rely on it.)
|
||||||
|
*
|
||||||
|
* The token location is attached to the run-time
|
||||||
|
* typecast, not to the Const, for the convenience of
|
||||||
|
* pg_stat_statements (which doesn't want these constructs
|
||||||
|
* to appear to be replaceable constants).
|
||||||
*/
|
*/
|
||||||
Node *n;
|
Node *n;
|
||||||
n = makeStringConstCast("now", @1, SystemTypeName("text"));
|
n = makeStringConstCast("now", -1, SystemTypeName("text"));
|
||||||
$$ = makeTypeCast(n, SystemTypeName("date"), -1);
|
$$ = makeTypeCast(n, SystemTypeName("date"), @1);
|
||||||
}
|
}
|
||||||
| CURRENT_TIME
|
| CURRENT_TIME
|
||||||
{
|
{
|
||||||
@ -11246,8 +11251,8 @@ func_expr: func_name '(' ')' over_clause
|
|||||||
* See comments for CURRENT_DATE.
|
* See comments for CURRENT_DATE.
|
||||||
*/
|
*/
|
||||||
Node *n;
|
Node *n;
|
||||||
n = makeStringConstCast("now", @1, SystemTypeName("text"));
|
n = makeStringConstCast("now", -1, SystemTypeName("text"));
|
||||||
$$ = makeTypeCast(n, SystemTypeName("timetz"), -1);
|
$$ = makeTypeCast(n, SystemTypeName("timetz"), @1);
|
||||||
}
|
}
|
||||||
| CURRENT_TIME '(' Iconst ')'
|
| CURRENT_TIME '(' Iconst ')'
|
||||||
{
|
{
|
||||||
@ -11257,10 +11262,10 @@ func_expr: func_name '(' ')' over_clause
|
|||||||
*/
|
*/
|
||||||
Node *n;
|
Node *n;
|
||||||
TypeName *d;
|
TypeName *d;
|
||||||
n = makeStringConstCast("now", @1, SystemTypeName("text"));
|
n = makeStringConstCast("now", -1, SystemTypeName("text"));
|
||||||
d = SystemTypeName("timetz");
|
d = SystemTypeName("timetz");
|
||||||
d->typmods = list_make1(makeIntConst($3, @3));
|
d->typmods = list_make1(makeIntConst($3, @3));
|
||||||
$$ = makeTypeCast(n, d, -1);
|
$$ = makeTypeCast(n, d, @1);
|
||||||
}
|
}
|
||||||
| CURRENT_TIMESTAMP
|
| CURRENT_TIMESTAMP
|
||||||
{
|
{
|
||||||
@ -11287,10 +11292,10 @@ func_expr: func_name '(' ')' over_clause
|
|||||||
*/
|
*/
|
||||||
Node *n;
|
Node *n;
|
||||||
TypeName *d;
|
TypeName *d;
|
||||||
n = makeStringConstCast("now", @1, SystemTypeName("text"));
|
n = makeStringConstCast("now", -1, SystemTypeName("text"));
|
||||||
d = SystemTypeName("timestamptz");
|
d = SystemTypeName("timestamptz");
|
||||||
d->typmods = list_make1(makeIntConst($3, @3));
|
d->typmods = list_make1(makeIntConst($3, @3));
|
||||||
$$ = makeTypeCast(n, d, -1);
|
$$ = makeTypeCast(n, d, @1);
|
||||||
}
|
}
|
||||||
| LOCALTIME
|
| LOCALTIME
|
||||||
{
|
{
|
||||||
@ -11299,8 +11304,8 @@ func_expr: func_name '(' ')' over_clause
|
|||||||
* See comments for CURRENT_DATE.
|
* See comments for CURRENT_DATE.
|
||||||
*/
|
*/
|
||||||
Node *n;
|
Node *n;
|
||||||
n = makeStringConstCast("now", @1, SystemTypeName("text"));
|
n = makeStringConstCast("now", -1, SystemTypeName("text"));
|
||||||
$$ = makeTypeCast((Node *)n, SystemTypeName("time"), -1);
|
$$ = makeTypeCast((Node *)n, SystemTypeName("time"), @1);
|
||||||
}
|
}
|
||||||
| LOCALTIME '(' Iconst ')'
|
| LOCALTIME '(' Iconst ')'
|
||||||
{
|
{
|
||||||
@ -11310,10 +11315,10 @@ func_expr: func_name '(' ')' over_clause
|
|||||||
*/
|
*/
|
||||||
Node *n;
|
Node *n;
|
||||||
TypeName *d;
|
TypeName *d;
|
||||||
n = makeStringConstCast("now", @1, SystemTypeName("text"));
|
n = makeStringConstCast("now", -1, SystemTypeName("text"));
|
||||||
d = SystemTypeName("time");
|
d = SystemTypeName("time");
|
||||||
d->typmods = list_make1(makeIntConst($3, @3));
|
d->typmods = list_make1(makeIntConst($3, @3));
|
||||||
$$ = makeTypeCast((Node *)n, d, -1);
|
$$ = makeTypeCast((Node *)n, d, @1);
|
||||||
}
|
}
|
||||||
| LOCALTIMESTAMP
|
| LOCALTIMESTAMP
|
||||||
{
|
{
|
||||||
@ -11322,8 +11327,8 @@ func_expr: func_name '(' ')' over_clause
|
|||||||
* See comments for CURRENT_DATE.
|
* See comments for CURRENT_DATE.
|
||||||
*/
|
*/
|
||||||
Node *n;
|
Node *n;
|
||||||
n = makeStringConstCast("now", @1, SystemTypeName("text"));
|
n = makeStringConstCast("now", -1, SystemTypeName("text"));
|
||||||
$$ = makeTypeCast(n, SystemTypeName("timestamp"), -1);
|
$$ = makeTypeCast(n, SystemTypeName("timestamp"), @1);
|
||||||
}
|
}
|
||||||
| LOCALTIMESTAMP '(' Iconst ')'
|
| LOCALTIMESTAMP '(' Iconst ')'
|
||||||
{
|
{
|
||||||
@ -11333,10 +11338,10 @@ func_expr: func_name '(' ')' over_clause
|
|||||||
*/
|
*/
|
||||||
Node *n;
|
Node *n;
|
||||||
TypeName *d;
|
TypeName *d;
|
||||||
n = makeStringConstCast("now", @1, SystemTypeName("text"));
|
n = makeStringConstCast("now", -1, SystemTypeName("text"));
|
||||||
d = SystemTypeName("timestamp");
|
d = SystemTypeName("timestamp");
|
||||||
d->typmods = list_make1(makeIntConst($3, @3));
|
d->typmods = list_make1(makeIntConst($3, @3));
|
||||||
$$ = makeTypeCast(n, d, -1);
|
$$ = makeTypeCast(n, d, @1);
|
||||||
}
|
}
|
||||||
| CURRENT_ROLE
|
| CURRENT_ROLE
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user