* 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
| 4556 | * we can't get there from a cast: our typmodin will have caught it already. |
| 4557 | */ |
| 4558 | Node * |
| 4559 | TemporalSimplify(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 |
no test coverage detected