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 1olCzU-0008Bn-7T for pgsql-general@arkaria.postgresql.org; Wed, 19 Oct 2022 17:36:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1olCzT-0003hF-2K for pgsql-general@arkaria.postgresql.org; Wed, 19 Oct 2022 17:36:27 +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 1olCzS-0003h6-Na for pgsql-general@lists.postgresql.org; Wed, 19 Oct 2022 17:36:26 +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 1olCzO-0008MB-L8 for pgsql-general@lists.postgresql.org; Wed, 19 Oct 2022 17:36:25 +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 723C26C7D9 for ; Wed, 19 Oct 2022 17:36:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=io7m.com; s=mail; t=1666200978; bh=D8eSp0U7DAPaXKQtA2hjrQjRZLHjvQl8T3L4ewui4EA=; h=Date:From:To:Subject:From; b=YicomvnhtxZBHlxCoTcjOVEuO1vhMFTcagZC0Jwmg0Om6RHEmqNQaKmR6fzGf29jB hCP6Aa4H/suYccv07sVjO4kjCYUCi/7dwnT2niWv1g10GLmkn5OcFIvlB7bzknq4sb Zzr0XBNfMzVCWc4qPnjpFIu15IRHVviLmOlx6HK0/Y9A24hlBRO9nROR2uPXRWv3Nn bQN0A8jTyET86YjsRUFXRgYmD6wzMQPAx9x0FGgRZkATzbgOoQvphrS8CfmJliR3fD M3FGjjNWYPZF2JQE4mAB4riosJuGXsD4yA55fsfPGhN8wAU/IvcsNoMiTpLoDw4UC0 UgdJNH2H2ifIg== Date: Wed, 19 Oct 2022 17:32:25 +0000 From: Mark Raynsford To: pgsql-general@lists.postgresql.org Subject: Column value derived from generated column in INSERT? Message-ID: <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 Hello! I'd like to be able to do something sort of analogous to this: create table t ( x integer not null generated always as identity, y integer not null ); insert into t (y) values (t.x * 2); In the real project, the "t.x * 2" expression is obviously something a lot more complex, but I think it illustrates the point: I'd like to be able to refer to the generated value of a column within the INSERT statement that's going to cause it to be generated. Is there a way to do this with a single statement right now? I can think of various ways to do it with multiple statements, but a single statement would be preferable. -- Mark Raynsford | https://www.io7m.com