Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aVMbg-0005Ex-C2 for pgsql-bugs@arkaria.postgresql.org; Mon, 15 Feb 2016 17:06:40 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aVMbf-00081m-VF for pgsql-bugs@arkaria.postgresql.org; Mon, 15 Feb 2016 17:06:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aUW1w-0000KR-BA for pgsql-bugs@postgresql.org; Sat, 13 Feb 2016 08:58:16 +0000 Received: from mx.kwnet.at ([91.114.64.156] helo=sv01samba.kwnet.local) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1aUW1t-0001zx-7H for pgsql-bugs@postgresql.org; Sat, 13 Feb 2016 08:58:15 +0000 Received: from [192.168.10.42] by sv01samba.kwnet.local with esmtpsa (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1aUW1o-0006xD-KP; Sat, 13 Feb 2016 09:58:08 +0100 Subject: Re: BUG #13938: CAST error on Index "function must be immutable" To: Tom Lane References: <20160209144201.2572.15861@wrigleys.postgresql.org> <14233.1455038154@sss.pgh.pa.us> Cc: pgsql-bugs@postgresql.org From: =?UTF-8?Q?Kurt_Wei=c3=9f?= Message-ID: <56BEF020.1080305@kwnet.at> Date: Sat, 13 Feb 2016 09:58:08 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <14233.1455038154@sss.pgh.pa.us> Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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