Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hlDt1-0003Zk-QZ for pgsql-bugs@arkaria.postgresql.org; Wed, 10 Jul 2019 14:47:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hlDt0-0003ZM-J2 for pgsql-bugs@arkaria.postgresql.org; Wed, 10 Jul 2019 14:47:58 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hlDt0-0003Z7-7O for pgsql-bugs@lists.postgresql.org; Wed, 10 Jul 2019 14:47:58 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hlDsx-0003uS-38 for pgsql-bugs@lists.postgresql.org; Wed, 10 Jul 2019 14:47:57 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x6AElqaL017504; Wed, 10 Jul 2019 10:47:52 -0400 From: Tom Lane To: Manuel Rigger cc: PostgreSQL mailing lists Subject: Re: Generated column and string concatenation issue In-reply-to: References: Comments: In-reply-to Manuel Rigger message dated "Wed, 10 Jul 2019 16:22:09 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <17502.1562770072.1@sss.pgh.pa.us> Date: Wed, 10 Jul 2019 10:47:52 -0400 Message-ID: <17503.1562770072@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Manuel Rigger writes: > Consider the following statement: > CREATE TABLE t0(c0 TEXT GENERATED ALWAYS AS (('abc' || 1)) STORED); -- > unexpected: generation expression is not immutable No, that's not a bug. What you've got is "text || integer", which requires an integer-to-text coercion, which isn't necessarily immutable. (Well, actually, integer-to-text is immutable. But the particular operator you're getting here is textanycat which accepts anything on the RHS, so it has to be marked stable which is our worst-case assumption for the stability of I/O conversions. As an example, timestamp-to-text's results vary with the DateStyle GUC so that one definitely isn't immutable.) You could imagine different factorizations of this functionality that might allow the specific RHS type to be taken into account, but the actual details of how to make that happen aren't very clear, and changing it might have other downsides. Anyway the short answer is that you should have done CREATE TABLE t0(c0 TEXT GENERATED ALWAYS AS (('abc' || '1')) STORED); which would resolve as "text || text" which is immutable. The explicit cast that you showed also dodges the problem by not relying on textanycat. regards, tom lane