aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/datetime.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils/adt/datetime.c')
-rw-r--r--src/backend/utils/adt/datetime.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 07e43a60fe5..f495c3f0109 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -23,6 +23,8 @@
#include "catalog/pg_type.h"
#include "funcapi.h"
#include "miscadmin.h"
+#include "nodes/nodeFuncs.h"
+#include "parser/parse_clause.h"
#include "utils/builtins.h"
#include "utils/date.h"
#include "utils/datetime.h"
@@ -4142,6 +4144,39 @@ CheckDateTokenTables(void)
}
/*
+ * Helper for temporal protransform functions. Types time, timetz, timestamp
+ * and timestamptz each have a range of allowed precisions. An unspecified
+ * precision is rigorously equivalent to the highest specifiable precision.
+ */
+Node *
+TemporalTransform(int32 max_precis, Node *node)
+{
+ FuncExpr *expr = (FuncExpr *) node;
+ Node *typmod;
+ Node *ret = NULL;
+
+ if (!IsA(expr, FuncExpr))
+ return ret;
+
+ Assert(list_length(expr->args) == 2);
+ typmod = lsecond(expr->args);
+
+ if (IsA(typmod, Const))
+ {
+ Node *source = linitial(expr->args);
+ int32 old_precis = exprTypmod(source);
+ int32 new_precis = DatumGetInt32(((Const *) typmod)->constvalue);
+
+ if (new_precis == -1 ||
+ new_precis == max_precis ||
+ (old_precis != -1 && new_precis >= old_precis))
+ ret = relabel_to_typmod(source, new_precis);
+ }
+
+ return ret;
+}
+
+/*
* This function gets called during timezone config file load or reload
* to create the final array of timezone tokens. The argument array
* is already sorted in name order. The data is converted to datetkn