Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitc1943db

Browse files
committed
Fix pg_get_ruledef() so that negative numeric constants are parenthesized.
This is needed because :: casting binds more tightly than minus, so forexample -1::integer is not the same as (-1)::integer, and there are caseswhere the difference is important. In particular this caused a failurein SELECT DISTINCT ... ORDER BY ... where expressions that should havematched were seen as different by the parser; but I suspect that therecould be other cases where failure to parenthesize leads to subtlersemantic differences in reloaded rules. Per report from Alexandr Popov.
1 parent700af33 commitc1943db

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

‎src/backend/utils/adt/ruleutils.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.274 2008/05/12 00:00:51 alvherre Exp $
12+
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.275 2008/06/06 17:59:29 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -4479,10 +4479,19 @@ get_const_expr(Const *constval, deparse_context *context, int showtype)
44794479
*
44804480
* In reality we only need to defend against infinity and NaN,
44814481
* so we need not get too crazy about pattern matching here.
4482+
*
4483+
* There is a special-case gotcha: if the constant is signed,
4484+
* we need to parenthesize it, else the parser might see a
4485+
* leading plus/minus as binding less tightly than adjacent
4486+
* operators --- particularly, the cast that we might attach
4487+
* below.
44824488
*/
44834489
if (strspn(extval,"0123456789+-eE.")==strlen(extval))
44844490
{
4485-
appendStringInfoString(buf,extval);
4491+
if (extval[0]=='+'||extval[0]=='-')
4492+
appendStringInfo(buf,"(%s)",extval);
4493+
else
4494+
appendStringInfoString(buf,extval);
44864495
if (strcspn(extval,"eE.")!=strlen(extval))
44874496
isfloat= true;/* it looks like a float */
44884497
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp