MCPcopy Create free account
hub / github.com/apache/cloudberry / make_const

Function make_const

src/backend/parser/parse_node.c:351–468  ·  view source on GitHub ↗

* make_const * * Convert a Value node (as returned by the grammar) to a Const node * of the "natural" type for the constant. Note that this routine is * only used when there is no explicit cast for the constant, so we * have to guess what type is wanted. * * For string literals we produce a constant of type UNKNOWN ---- whose * representation is the same as cstring, but it indicates to la

Source from the content-addressed store, hash-verified

349 * too many examples that fail if we try.
350 */
351Const *
352make_const(ParseState *pstate, Value *value, int location)
353{
354 Const *con;
355 Datum val;
356 int64 val64;
357 Oid typeid;
358 int typelen;
359 bool typebyval;
360 ParseCallbackState pcbstate;
361
362 switch (nodeTag(value))
363 {
364 case T_Integer:
365 val = Int32GetDatum(intVal(value));
366
367 typeid = INT4OID;
368 typelen = sizeof(int32);
369 typebyval = true;
370 break;
371
372 case T_Float:
373 /* could be an oversize integer as well as a float ... */
374 if (scanint8(strVal(value), true, &val64))
375 {
376 /*
377 * It might actually fit in int32. Probably only INT_MIN can
378 * occur, but we'll code the test generally just to be sure.
379 */
380 int32 val32 = (int32) val64;
381
382 if (val64 == (int64) val32)
383 {
384 val = Int32GetDatum(val32);
385
386 typeid = INT4OID;
387 typelen = sizeof(int32);
388 typebyval = true;
389 }
390 else
391 {
392 val = Int64GetDatum(val64);
393
394 typeid = INT8OID;
395 typelen = sizeof(int64);
396 typebyval = FLOAT8PASSBYVAL; /* int8 and float8 alike */
397 }
398 }
399 else
400 {
401 /* arrange to report location if numeric_in() fails */
402 setup_parser_errposition_callback(&pcbstate, pstate, location);
403 val = DirectFunctionCall3(numeric_in,
404 CStringGetDatum(strVal(value)),
405 ObjectIdGetDatum(InvalidOid),
406 Int32GetDatum(-1));
407 cancel_parser_errposition_callback(&pcbstate);
408

Callers 1

transformExprRecurseFunction · 0.85

Calls 8

Int32GetDatumFunction · 0.85
scanint8Function · 0.85
CStringGetDatumFunction · 0.85
ObjectIdGetDatumFunction · 0.85
makeConstFunction · 0.85
Int64GetDatumFunction · 0.50

Tested by

no test coverage detected