aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_node.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2005-04-23 18:35:12 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2005-04-23 18:35:12 +0000
commitb1faf3624bf4a4fc0e78dc551d9dd4d491339300 (patch)
tree138307a5ba3f8f70daaab20e2924ce4512b3d651 /src/backend/parser/parse_node.c
parentd79eeef38b075025c68ddf7debba4224b6aeabc8 (diff)
downloadpostgresql-b1faf3624bf4a4fc0e78dc551d9dd4d491339300.tar.gz
postgresql-b1faf3624bf4a4fc0e78dc551d9dd4d491339300.zip
Allow -2147483648 to be treated as an INT4 rather than INT8 constant.
Per discussion with Paul Edwards.
Diffstat (limited to 'src/backend/parser/parse_node.c')
-rw-r--r--src/backend/parser/parse_node.c35
1 files changed, 26 insertions, 9 deletions
diff --git a/src/backend/parser/parse_node.c b/src/backend/parser/parse_node.c
index ed9bf5202bb..921da9a04a5 100644
--- a/src/backend/parser/parse_node.c
+++ b/src/backend/parser/parse_node.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/parse_node.c,v 1.87 2004/12/31 22:00:27 pgsql Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/parse_node.c,v 1.88 2005/04/23 18:35:12 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -276,9 +276,9 @@ transformArraySubscripts(ParseState *pstate,
* Explicit "NULL" constants are also typed as UNKNOWN.
*
* For integers and floats we produce int4, int8, or numeric depending
- * on the value of the number. XXX This should include int2 as well,
- * but additional cleanup is needed before we can do that; else cases
- * like "WHERE int4var = 42" will fail to be indexable.
+ * on the value of the number. XXX We should produce int2 as well,
+ * but additional cleanup is needed before we can do that; there are
+ * too many examples that fail if we try.
*/
Const *
make_const(Value *value)
@@ -304,11 +304,28 @@ make_const(Value *value)
/* could be an oversize integer as well as a float ... */
if (scanint8(strVal(value), true, &val64))
{
- val = Int64GetDatum(val64);
-
- typeid = INT8OID;
- typelen = sizeof(int64);
- typebyval = false; /* XXX might change someday */
+ /*
+ * It might actually fit in int32. Probably only INT_MIN can
+ * occur, but we'll code the test generally just to be sure.
+ */
+ int32 val32 = (int32) val64;
+
+ if (val64 == (int64) val32)
+ {
+ val = Int32GetDatum(val32);
+
+ typeid = INT4OID;
+ typelen = sizeof(int32);
+ typebyval = true;
+ }
+ else
+ {
+ val = Int64GetDatum(val64);
+
+ typeid = INT8OID;
+ typelen = sizeof(int64);
+ typebyval = false; /* XXX might change someday */
+ }
}
else
{