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 1olEq7-0005lX-Kn for pgsql-general@arkaria.postgresql.org; Wed, 19 Oct 2022 19:34:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1olEq6-0003m2-Fy for pgsql-general@arkaria.postgresql.org; Wed, 19 Oct 2022 19:34:54 +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 1olEq6-0003lt-4X for pgsql-general@lists.postgresql.org; Wed, 19 Oct 2022 19:34:54 +0000 Received: from mail.io7m.com ([2001:19f0:5:752:f000::]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1olEq3-0000nL-RM for pgsql-general@lists.postgresql.org; Wed, 19 Oct 2022 19:34:53 +0000 Received: from sunflower.int.arc7.info (unknown [IPv6:2a02:390:7502:2:0:2:4:0]) by mail.io7m.com (Postfix) with ESMTPSA id B96056C993; Wed, 19 Oct 2022 19:34:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=io7m.com; s=mail; t=1666208089; bh=AuTAL++67v9VbBIyQzCtL+WuD074WnGGfbh6d5HLzMU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=AAY5juPxL1Grrxx12u7b4O3IlJhNNQURK2L4wAIhos4M1iQ7bl7NU2+c0OfpXzVUu PbR0vwP3pFBt3OnSXwQ2bIhsrejheQNlg3gssKKGhBAmRpPhklsB309btHrubDO8Kn rsKisJ+AZ3uheL8BnBgCvl8V8urBro7tv4e6R6SozWuMWyOl/wTOs86ZQh0JZVXrPr otdsIMLBBgKv7osAVV/FSzGQvCEYKjr2pb3huTt/E7Y/fK8ov+AXrPcgZYCJmYexK8 2i8fSpsEj7rkt66vG2l4cIMtZtXcjFXg1WjQDNMJbk3yxYu8ZY9RoxiWMcxbap+55s sTfM+mpNrGd4w== Date: Wed, 19 Oct 2022 19:30:57 +0000 From: Mark Raynsford To: "David G. Johnston" Cc: pgsql-general@lists.postgresql.org Subject: Re: Column value derived from generated column in INSERT? Message-ID: <20221019193057.39aff1c1@sunflower.int.arc7.info> In-Reply-To: References: <20221019173225.53d939f2@sunflower.int.arc7.info> Organization: io7m.com OpenPGP: id=2680A50EFD032007FABE8C87B0E4322EEE818BDE; url=https://www.io7m.com/#pgp MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2022-10-19T11:58:07 -0700 "David G. Johnston" wrote: > On Wed, Oct 19, 2022 at 10:36 AM Mark Raynsford > wrote: > > > insert into t (y) values (t.x * 2); > > > > I can think of various ways to do it with multiple statements, but a > > single statement would be preferable. > > > > > No, by extension of the documented constraint: "The generation expression > can refer to other columns in the table, but not other generated columns." > Hello! Just want to confirm that I wasn't misunderstood. The documentation in CREATE TABLE has the sentence you quoted above, and unless I'm misunderstanding that's saying that the expression used to generate values in GENERATED (ALWAYS AS) columns can't refer to other GENERATED columns. That's fine, but that's not what I was asking. In the table above, `x` is generated without references to other columns, but for the non-GENERATED `y` value, I want to refer to the value that `x` will have when I calculate a value for the `y` column in the INSERT statement. If that's not doable, that's fine, I just want to be sure. :) -- Mark Raynsford | https://www.io7m.com