pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kurt Weiß <kurt@kwnet.at>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #13938: CAST error on Index "function must be immutable"
Date: Sat, 13 Feb 2016 09:58:08 +0100
Message-ID: <56BEF020.1080305@kwnet.at> (raw)
In-Reply-To: <14233.1455038154@sss.pgh.pa.us>
References: <20160209144201.2572.15861@wrigleys.postgresql.org>
	<14233.1455038154@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

but the workaround is running well and get's rated as "IMMUTABLE" though 
returning timestamp and interval...
So maybe the allowness for setting the function in the workaround to 
immutable will be the bug?

--WORKAROUND START:

CREATE OR REPLACE FUNCTION ud_data_timestamp1(val TEXT) RETURNS 
TIMESTAMP WITH TIME ZONE AS $$
  BEGIN
    RETURN CAST($1 AS TIMESTAMP WITH TIME ZONE);
  END;
$$ LANGUAGE plpgsql IMMUTABLE;

CREATE OR REPLACE FUNCTION ud_data_timestamp2(val TEXT) RETURNS 
TIMESTAMP WITHOUT TIME ZONE AS $$
  BEGIN
    RETURN CAST($1 AS TIMESTAMP WITHOUT TIME ZONE);
  END;
$$ LANGUAGE plpgsql IMMUTABLE;

CREATE OR REPLACE FUNCTION ud_data_interval(val TEXT) RETURNS INTERVAL AS $$
  BEGIN
    RETURN CAST($1 AS INTERVAL);
  END;
$$ LANGUAGE plpgsql IMMUTABLE;

CREATE INDEX ud_data_DT_ZONE ON ud_data(ud_data_timestamp1(val)) WHERE 
i_type IN(5,6) AND (i_param & 4)=0;
CREATE INDEX ud_data_DT_GMT ON ud_data(ud_data_timestamp2(val)) WHERE 
i_type IN(5,6) AND (i_param & 4)=4;
CREATE INDEX ud_data_TIME ON ud_data(ud_data_interval(val)) WHERE i_type=10;

--WORKAROUND END


Am 09.02.2016 um 18:15 schrieb Tom Lane:
> kurt@kwnet.at writes:
>> CREATE TABLE ud_data (
>>   val TEXT,
>> );
>> CREATE INDEX ud_data_FLOAT ON ud_data(CAST(val AS FLOAT)) WHERE i_type=3;
>> --accepted as valid.
>> CREATE INDEX ud_data_TIME ON ud_data(CAST(val AS INTERVAL)) WHERE
>> i_type=10;
>> --results in error "functions in index expression must be marked IMMUTABLE"
> This is not a bug.  The cast from text to interval isn't immutable because
> its results may vary depending on the IntervalStyle setting.
>
>> --the same error when casting to TIMESTAMP (with or without time zone)
> Same, although it's DateStyle and/or TimeZone that affect this.
>
> 			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



view thread (4+ messages)  latest in thread

Message-ID: <56BEF020.1080305@kwnet.at>
Permalink:  ../56BEF020.1080305@kwnet.at/
Also on:    postgresql.org/message-id/56BEF020.1080305@kwnet.at

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: kurt@kwnet.at, tgl@sss.pgh.pa.us
  Subject: Re: BUG #13938: CAST error on Index "function must be immutable"
  In-Reply-To: <56BEF020.1080305@kwnet.at>
  References: <20160209144201.2572.15861@wrigleys.postgresql.org> <14233.1455038154@sss.pgh.pa.us> <56BEF020.1080305@kwnet.at>

* 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