aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend/utils/adt/ruleutils.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 4393f91c41f..3754b4981ed 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.274 2008/05/12 00:00:51 alvherre Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.275 2008/06/06 17:59:29 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -4479,10 +4479,19 @@ get_const_expr(Const *constval, deparse_context *context, int showtype)
*
* In reality we only need to defend against infinity and NaN,
* so we need not get too crazy about pattern matching here.
+ *
+ * There is a special-case gotcha: if the constant is signed,
+ * we need to parenthesize it, else the parser might see a
+ * leading plus/minus as binding less tightly than adjacent
+ * operators --- particularly, the cast that we might attach
+ * below.
*/
if (strspn(extval, "0123456789+-eE.") == strlen(extval))
{
- appendStringInfoString(buf, extval);
+ if (extval[0] == '+' || extval[0] == '-')
+ appendStringInfo(buf, "(%s)", extval);
+ else
+ appendStringInfoString(buf, extval);
if (strcspn(extval, "eE.") != strlen(extval))
isfloat = true; /* it looks like a float */
}