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

Function TemporalSimplify

src/backend/utils/adt/datetime.c:4558–4581  ·  view source on GitHub ↗

* Common code for temporal prosupport functions: simplify, if possible, * a call to a temporal type's length-coercion function. * * Types time, timetz, timestamp and timestamptz each have a range of allowed * precisions. An unspecified precision is rigorously equivalent to the * highest specifiable precision. We can replace the function call with a * no-op RelabelType if it is coercing to

Source from the content-addressed store, hash-verified

4556 * we can't get there from a cast: our typmodin will have caught it already.
4557 */
4558Node *
4559TemporalSimplify(int32 max_precis, Node *node)
4560{
4561 FuncExpr *expr = castNode(FuncExpr, node);
4562 Node *ret = NULL;
4563 Node *typmod;
4564
4565 Assert(list_length(expr->args) >= 2);
4566
4567 typmod = (Node *) lsecond(expr->args);
4568
4569 if (IsA(typmod, Const) && !((Const *) typmod)->constisnull)
4570 {
4571 Node *source = (Node *) linitial(expr->args);
4572 int32 old_precis = exprTypmod(source);
4573 int32 new_precis = DatumGetInt32(((Const *) typmod)->constvalue);
4574
4575 if (new_precis < 0 || new_precis == max_precis ||
4576 (old_precis >= 0 && new_precis >= old_precis))
4577 ret = relabel_to_typmod(source, new_precis);
4578 }
4579
4580 return ret;
4581}
4582
4583/*
4584 * This function gets called during timezone config file load or reload

Callers 2

timestamp_supportFunction · 0.85
time_supportFunction · 0.85

Calls 4

list_lengthFunction · 0.85
exprTypmodFunction · 0.85
DatumGetInt32Function · 0.85
relabel_to_typmodFunction · 0.85

Tested by

no test coverage detected