From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: marcus@cockroachlabs.com
Subject: BUG #17371: Immutable INTERVAL to TEXT cast can cause incorrect query results
Date: Wed, 19 Jan 2022 21:06:41 +0000
Message-ID: <17371-8f57e6e9ca5e35bf@postgresql.org> (raw)
The following bug has been logged on the website:
Bug reference: 17371
Logged by: Marcus Gartner
Email address: marcus@cockroachlabs.com
PostgreSQL version: 14.0
Operating system: macOS Big Sur 11.6
Description:
I believe casts from INTERVAL to TEXT (and other string-like types such as
CHAR, NAME, VARCHAR, and "char") should have a volatility of stable, not
immutable, because the results of these casts depend on IntervalStyle. As an
immutable cast, INTERVAL to TEXT casts are allowed in computed columns and
expression indexes, which can cause incorrect query results. For example:
SET IntervalStyle = 'postgres';
CREATE TABLE t (i INTERVAL);
INSERT INTO t SELECT i * '1 day'::INTERVAL FROM generate_series(1, 10000)
s(i);
CREATE INDEX i ON t((i::TEXT), i);
SET IntervalStyle = 'sql_standard';
-- Returns false.
SELECT i::TEXT = '5 days' FROM t WHERE i::TEXT = '5 days';
ANALYZE t;
-- Same query as above, now performing an index-only scan, returns true.
SELECT i::TEXT = '5 days' FROM t WHERE i::TEXT = '5 days';
DROP INDEX i;
-- Same query as above returns zero rows.
SELECT i::TEXT = '5 days' FROM t WHERE i::TEXT = '5 days';
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: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, marcus@cockroachlabs.com
Subject: Re: BUG #17371: Immutable INTERVAL to TEXT cast can cause incorrect query results
In-Reply-To: <17371-8f57e6e9ca5e35bf@postgresql.org>
* 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