From: Tom Lane <tgl@sss.pgh.pa.us>
To: email@piotr-stefaniak.me
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #14479: Casting non-constant values to INTERVAL DAY TO MINUTE doesn't truncate the seconds field
Date: Tue, 27 Dec 2016 15:00:43 -0500
Message-ID: <31017.1482868843@sss.pgh.pa.us> (raw)
In-Reply-To: <26632.1482862368@sss.pgh.pa.us>
References: <20161227172307.10135.7747@wrigleys.postgresql.org>
<26632.1482862368@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
I wrote:
> I've not figured out exactly what's broken about interval_transform;
> the bit-twiddling looks a bit fishy, but it may be that that's fine
> and there's simply a thinko in the logic about which conversions
> are no-ops.
There seem to be multiple problems here.
One is that this innocent-looking assumption:
* Temporally-smaller fields occupy higher positions in the range
* bitmap.
is bunkum, as a quick look into dt.h confirms:
#define MONTH 1
#define YEAR 2
#define DAY 3
#define HOUR 10
#define MINUTE 11
#define SECOND 12
Don't ask me why MONTH was listed before YEAR, but it is, and we don't
really have the freedom to change these codes (especially not in the
back branches). This function will just have to cope. However, that
doesn't impact your specific bug; it means that casting INTERVAL MONTH
to INTERVAL YEAR is mistakenly treated as a no-op.
The other problem is that it's comparing the result of fls() to the
constant SECOND, but that's not right because fls(1 << k) produces k+1
not k. So it's mistakenly reading the cast to INTERVAL DAY TO MINUTE
as a cast to INTERVAL DAY TO SECOND, which indeed would be a no-op.
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, email@piotr-stefaniak.me
Subject: Re: BUG #14479: Casting non-constant values to INTERVAL DAY TO MINUTE doesn't truncate the seconds field
In-Reply-To: <31017.1482868843@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox