diff options
author | Robert Haas <rhaas@postgresql.org> | 2012-02-09 12:21:57 -0500 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2012-02-09 12:24:22 -0500 |
commit | 6656588575abd13016989be1a276b1b60be49b69 (patch) | |
tree | c57cee1508cae1e66af1d5cb3a1c1d77ae46f524 | |
parent | d7ea9193d18d29bea82b30604cdd087e90c5ee27 (diff) | |
download | postgresql-6656588575abd13016989be1a276b1b60be49b69.tar.gz postgresql-6656588575abd13016989be1a276b1b60be49b69.zip |
Improve interval_transform function to detect a few more cases.
Noah Misch, per a review comment from me.
-rw-r--r-- | src/backend/utils/adt/timestamp.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index 44a3a922ece..12af7f69f69 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -958,6 +958,7 @@ interval_transform(PG_FUNCTION_ARGS) int new_range = INTERVAL_RANGE(new_typmod); int new_precis = INTERVAL_PRECISION(new_typmod); int new_range_fls; + int old_range_fls; if (old_typmod == -1) { @@ -974,12 +975,16 @@ interval_transform(PG_FUNCTION_ARGS) * Temporally-smaller fields occupy higher positions in the range * bitmap. Since only the temporally-smallest bit matters for length * coercion purposes, we compare the last-set bits in the ranges. + * Precision, which is to say, sub-second precision, only affects + * ranges that include SECOND. */ new_range_fls = fls(new_range); + old_range_fls = fls(old_range); if (new_typmod == -1 || ((new_range_fls >= SECOND || - new_range_fls >= fls(old_range)) && - (new_precis >= MAX_INTERVAL_PRECISION || + new_range_fls >= old_range_fls) && + (old_range_fls < SECOND || + new_precis >= MAX_INTERVAL_PRECISION || new_precis >= old_precis))) ret = relabel_to_typmod(source, new_typmod); } |