Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 69c7a98

Browse filesBrowse 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 01f7808 commit 69c7a98
Copy full SHA for 69c7a98

File tree

Expand file treeCollapse file tree

1 file changed

+26
-21
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+26
-21
lines changed

‎src/backend/parser/gram.y

Copy file name to clipboardExpand all lines: src/backend/parser/gram.y
+26-21Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11361,18 +11361,18 @@ func_expr: func_application within_group_clause filter_clause over_clause
1136111361
;
1136211362

1136311363
/*
11364-
* As func_expr but does not accept WINDOW functions directly (they
11365-
* can still be contained in arguments for functions etc.)
11366-
* Use this when window expressions are not allowed, so to disambiguate
11367-
* the grammar. (e.g. in CREATE INDEX)
11364+
* As func_expr but does not accept WINDOW functions directly
11365+
* (but they can still be contained in arguments for functions etc).
11366+
* Use this when window expressions are not allowed, where needed to
11367+
* disambiguate the grammar (e.g. in CREATE INDEX).
1136811368
*/
1136911369
func_expr_windowless:
1137011370
func_application { $$ = $1; }
1137111371
| func_expr_common_subexpr { $$ = $1; }
1137211372
;
1137311373

1137411374
/*
11375-
* Special expression
11375+
* Special expressions that are considered to be functions.
1137611376
*/
1137711377
func_expr_common_subexpr:
1137811378
COLLATION FOR '(' a_expr ')'
@@ -11397,10 +11397,15 @@ func_expr_common_subexpr:
1139711397
* of type-input conversion functions. (As of PG 7.3
1139811398
* that is actually possible, but not clear that we want
1139911399
* to rely on it.)
11400+
*
11401+
* The token location is attached to the run-time
11402+
* typecast, not to the Const, for the convenience of
11403+
* pg_stat_statements (which doesn't want these constructs
11404+
* to appear to be replaceable constants).
1140011405
*/
1140111406
Node *n;
11402-
n = makeStringConstCast("now", @1, SystemTypeName("text"));
11403-
$$ = makeTypeCast(n, SystemTypeName("date"), -1);
11407+
n = makeStringConstCast("now", -1, SystemTypeName("text"));
11408+
$$ = makeTypeCast(n, SystemTypeName("date"), @1);
1140411409
}
1140511410
| CURRENT_TIME
1140611411
{
@@ -11409,8 +11414,8 @@ func_expr_common_subexpr:
1140911414
* See comments for CURRENT_DATE.
1141011415
*/
1141111416
Node *n;
11412-
n = makeStringConstCast("now", @1, SystemTypeName("text"));
11413-
$$ = makeTypeCast(n, SystemTypeName("timetz"), -1);
11417+
n = makeStringConstCast("now", -1, SystemTypeName("text"));
11418+
$$ = makeTypeCast(n, SystemTypeName("timetz"), @1);
1141411419
}
1141511420
| CURRENT_TIME '(' Iconst ')'
1141611421
{
@@ -11420,10 +11425,10 @@ func_expr_common_subexpr:
1142011425
*/
1142111426
Node *n;
1142211427
TypeName *d;
11423-
n = makeStringConstCast("now", @1, SystemTypeName("text"));
11428+
n = makeStringConstCast("now", -1, SystemTypeName("text"));
1142411429
d = SystemTypeName("timetz");
1142511430
d->typmods = list_make1(makeIntConst($3, @3));
11426-
$$ = makeTypeCast(n, d, -1);
11431+
$$ = makeTypeCast(n, d, @1);
1142711432
}
1142811433
| CURRENT_TIMESTAMP
1142911434
{
@@ -11441,10 +11446,10 @@ func_expr_common_subexpr:
1144111446
*/
1144211447
Node *n;
1144311448
TypeName *d;
11444-
n = makeStringConstCast("now", @1, SystemTypeName("text"));
11449+
n = makeStringConstCast("now", -1, SystemTypeName("text"));
1144511450
d = SystemTypeName("timestamptz");
1144611451
d->typmods = list_make1(makeIntConst($3, @3));
11447-
$$ = makeTypeCast(n, d, -1);
11452+
$$ = makeTypeCast(n, d, @1);
1144811453
}
1144911454
| LOCALTIME
1145011455
{
@@ -11453,8 +11458,8 @@ func_expr_common_subexpr:
1145311458
* See comments for CURRENT_DATE.
1145411459
*/
1145511460
Node *n;
11456-
n = makeStringConstCast("now", @1, SystemTypeName("text"));
11457-
$$ = makeTypeCast((Node *)n, SystemTypeName("time"), -1);
11461+
n = makeStringConstCast("now", -1, SystemTypeName("text"));
11462+
$$ = makeTypeCast((Node *)n, SystemTypeName("time"), @1);
1145811463
}
1145911464
| LOCALTIME '(' Iconst ')'
1146011465
{
@@ -11464,10 +11469,10 @@ func_expr_common_subexpr:
1146411469
*/
1146511470
Node *n;
1146611471
TypeName *d;
11467-
n = makeStringConstCast("now", @1, SystemTypeName("text"));
11472+
n = makeStringConstCast("now", -1, SystemTypeName("text"));
1146811473
d = SystemTypeName("time");
1146911474
d->typmods = list_make1(makeIntConst($3, @3));
11470-
$$ = makeTypeCast((Node *)n, d, -1);
11475+
$$ = makeTypeCast((Node *)n, d, @1);
1147111476
}
1147211477
| LOCALTIMESTAMP
1147311478
{
@@ -11476,8 +11481,8 @@ func_expr_common_subexpr:
1147611481
* See comments for CURRENT_DATE.
1147711482
*/
1147811483
Node *n;
11479-
n = makeStringConstCast("now", @1, SystemTypeName("text"));
11480-
$$ = makeTypeCast(n, SystemTypeName("timestamp"), -1);
11484+
n = makeStringConstCast("now", -1, SystemTypeName("text"));
11485+
$$ = makeTypeCast(n, SystemTypeName("timestamp"), @1);
1148111486
}
1148211487
| LOCALTIMESTAMP '(' Iconst ')'
1148311488
{
@@ -11487,10 +11492,10 @@ func_expr_common_subexpr:
1148711492
*/
1148811493
Node *n;
1148911494
TypeName *d;
11490-
n = makeStringConstCast("now", @1, SystemTypeName("text"));
11495+
n = makeStringConstCast("now", -1, SystemTypeName("text"));
1149111496
d = SystemTypeName("timestamp");
1149211497
d->typmods = list_make1(makeIntConst($3, @3));
11493-
$$ = makeTypeCast(n, d, -1);
11498+
$$ = makeTypeCast(n, d, @1);
1149411499
}
1149511500
| CURRENT_ROLE
1149611501
{

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.