Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pbHP4-0002AZ-7F for pgsql-general@arkaria.postgresql.org; Sun, 12 Mar 2023 08:50:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pbHP1-0001me-7S for pgsql-general@arkaria.postgresql.org; Sun, 12 Mar 2023 08:50:03 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pbHP0-0001mV-QM for pgsql-general@lists.postgresql.org; Sun, 12 Mar 2023 08:50:02 +0000 Received: from mail-4322.protonmail.ch ([185.70.43.22]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pbHOx-0007PK-NL for pgsql-general@postgresql.org; Sun, 12 Mar 2023 08:50:01 +0000 Date: Sun, 12 Mar 2023 08:49:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1678610997; x=1678870197; bh=T+azzbv++1zbMG21vvXis1pH+gBD1TlHnTijjQDtRXY=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=PdhoYpEPW0GGVXOpLgmX0goTUSFt0/5Z86ncuDhmoW0/oEDJK7saL+ktQDChYzOW/ 80LN7kNvaCKQ4wjAgdFt/eJ9NnGdWMYbo07pkFFrlNq67ZrAjho9sgamacubV9RrWd Dglw4Bn7hRiBQ0jFkwXvgSdEWxARRl3rm58RhDFdmObSyOjWx4WqcdRUKftR7tKBL2 u7XuettpmDkklrdlNv2SCyhBwDYJYPAAtTdyXnhyOZ1eBQSqpdyp2z6luoj3MFM06X UUX4sbBFu5K2+PklTqWsi0Ah1LxM0dcOKidalr23NXJx2/loA6K/VLq9M+gYCii/5M 5SRxvlwU5vnVw== To: Tom Lane From: Martijn de Munnik Cc: pgsql-general@postgresql.org Subject: Re: ERROR: only immutable functions supported in continuous aggregate view Message-ID: <5a6b29d8-7223-5959-1e6e-c84468525f6f@protonmail.com> In-Reply-To: <1171919.1678549672@sss.pgh.pa.us> References: <0b21034b-3fa8-16b3-c65b-1ef6b67c4da2@protonmail.com> <1171919.1678549672@sss.pgh.pa.us> Feedback-ID: 4917635:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Ok, now I understand, thank you. My solution is to create materialized view with intermediate values and the create a normal view on top that uses the intermediate values and the jsonb_build_object function to create the desired result. Kind regards, Martijn de Munnik On 2023-03-11 16:47, Tom Lane wrote: > Martijn de Munnik writes: >> The error is caused by the jsonb_build_object function, is there any >> reason why this function is not IMMUTABLE? > It can invoke arbitrary datatype output functions, some of which are > not immutable. We unfortunately lack any infrastructure that would > allow reasoning that "all the types used in this specific invocation > have immutable output functions, so it'd be OK to consider this > invocation immutable". So we have to assume the worst when labeling > jsonb_build_object. (Even if we had such infrastructure, I doubt > it would save you in this use-case, because it looks like some of > the values you're converting are timestamps, which respond to the > DateStyle and TimeZone settings.) > > You could, on these grounds, argue that jsonb_build_object and other > functions with this problem actually need to be VOLATILE. But we've > established a project convention that I/O functions should be at > worst STABLE, allowing calling functions to be STABLE as well. > > =09=09=09regards, tom lane