Skip to content

Commit 6656588

Browse files
committed
Improve interval_transform function to detect a few more cases.
Noah Misch, per a review comment from me.
1 parent d7ea919 commit 6656588

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/backend/utils/adt/timestamp.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,7 @@ interval_transform(PG_FUNCTION_ARGS)
958958
int new_range = INTERVAL_RANGE(new_typmod);
959959
int new_precis = INTERVAL_PRECISION(new_typmod);
960960
int new_range_fls;
961+
int old_range_fls;
961962

962963
if (old_typmod == -1)
963964
{
@@ -974,12 +975,16 @@ interval_transform(PG_FUNCTION_ARGS)
974975
* Temporally-smaller fields occupy higher positions in the range
975976
* bitmap. Since only the temporally-smallest bit matters for length
976977
* coercion purposes, we compare the last-set bits in the ranges.
978+
* Precision, which is to say, sub-second precision, only affects
979+
* ranges that include SECOND.
977980
*/
978981
new_range_fls = fls(new_range);
982+
old_range_fls = fls(old_range);
979983
if (new_typmod == -1 ||
980984
((new_range_fls >= SECOND ||
981-
new_range_fls >= fls(old_range)) &&
982-
(new_precis >= MAX_INTERVAL_PRECISION ||
985+
new_range_fls >= old_range_fls) &&
986+
(old_range_fls < SECOND ||
987+
new_precis >= MAX_INTERVAL_PRECISION ||
983988
new_precis >= old_precis)))
984989
ret = relabel_to_typmod(source, new_typmod);
985990
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy