88 *
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/backend/parser/parse_node.c,v 1.87 2004/12/31 22:00:27 pgsql Exp $
11+ * $PostgreSQL: pgsql/src/backend/parser/parse_node.c,v 1.88 2005/04/23 18:35:12 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -276,9 +276,9 @@ transformArraySubscripts(ParseState *pstate,
276276 * Explicit "NULL" constants are also typed as UNKNOWN.
277277 *
278278 * For integers and floats we produce int4, int8, or numeric depending
279- * on the value of the number. XXX This should include int2 as well,
280- * but additional cleanup is needed before we can do that; else cases
281- * like "WHERE int4var = 42" will fail to be indexable .
279+ * on the value of the number. XXX We should produce int2 as well,
280+ * but additional cleanup is needed before we can do that; there are
281+ * too many examples that fail if we try .
282282 */
283283Const *
284284make_const (Value * value )
@@ -304,11 +304,28 @@ make_const(Value *value)
304304 /* could be an oversize integer as well as a float ... */
305305 if (scanint8 (strVal (value ), true, & val64 ))
306306 {
307- val = Int64GetDatum (val64 );
308-
309- typeid = INT8OID ;
310- typelen = sizeof (int64 );
311- typebyval = false; /* XXX might change someday */
307+ /*
308+ * It might actually fit in int32. Probably only INT_MIN can
309+ * occur, but we'll code the test generally just to be sure.
310+ */
311+ int32 val32 = (int32 ) val64 ;
312+
313+ if (val64 == (int64 ) val32 )
314+ {
315+ val = Int32GetDatum (val32 );
316+
317+ typeid = INT4OID ;
318+ typelen = sizeof (int32 );
319+ typebyval = true;
320+ }
321+ else
322+ {
323+ val = Int64GetDatum (val64 );
324+
325+ typeid = INT8OID ;
326+ typelen = sizeof (int64 );
327+ typebyval = false; /* XXX might change someday */
328+ }
312329 }
313330 else
314331 {
0 commit comments