Skip to content

Commit b1faf36

Browse files
committed
Allow -2147483648 to be treated as an INT4 rather than INT8 constant.
Per discussion with Paul Edwards.
1 parent d79eeef commit b1faf36

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

src/backend/parser/parse_node.c

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
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
*/
283283
Const *
284284
make_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

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy