1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-30 21:42:05 +03:00

Add transform functions for various temporal typmod coercisions.

This enables ALTER TABLE to skip table and index rebuilds in some cases.

Noah Misch, with trivial changes by me.
This commit is contained in:
Robert Haas
2012-02-08 09:33:02 -05:00
parent 1a01560cbb
commit c13897983a
8 changed files with 150 additions and 6 deletions

View File

@ -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"
@ -4141,6 +4143,39 @@ CheckDateTokenTables(void)
return ok;
}
/*
* 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