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 1pb1Ry-0000xu-KJ for pgsql-general@arkaria.postgresql.org; Sat, 11 Mar 2023 15:48:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pb1Rx-0006uZ-4a for pgsql-general@arkaria.postgresql.org; Sat, 11 Mar 2023 15:48:01 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pb1Rw-0006uQ-Or for pgsql-general@lists.postgresql.org; Sat, 11 Mar 2023 15:48:00 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pb1Rq-0006cY-7P for pgsql-general@postgresql.org; Sat, 11 Mar 2023 15:47:59 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 32BFlqgg1171920; Sat, 11 Mar 2023 10:47:52 -0500 From: Tom Lane To: Martijn de Munnik cc: pgsql-general@postgresql.org Subject: Re: ERROR: only immutable functions supported in continuous aggregate view In-reply-to: <0b21034b-3fa8-16b3-c65b-1ef6b67c4da2@protonmail.com> References: <0b21034b-3fa8-16b3-c65b-1ef6b67c4da2@protonmail.com> Comments: In-reply-to Martijn de Munnik message dated "Sat, 11 Mar 2023 14:04:54 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1171918.1678549672.1@sss.pgh.pa.us> Date: Sat, 11 Mar 2023 10:47:52 -0500 Message-ID: <1171919.1678549672@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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. regards, tom lane