Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dz62r-0006Yb-La for pgsql-hackers@arkaria.postgresql.org; Mon, 02 Oct 2017 19:06:25 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dz62r-0006if-8U for pgsql-hackers@arkaria.postgresql.org; Mon, 02 Oct 2017 19:06:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dz61I-0003uR-21 for pgsql-hackers@postgresql.org; Mon, 02 Oct 2017 19:04:48 +0000 Received: from sub4.mail.dreamhost.com ([69.163.253.135] helo=homiemail-a24.g.dreamhost.com) by magus.postgresql.org with esmtps (TLS1.1:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1dz61E-0000Nu-Tj for pgsql-hackers@postgresql.org; Mon, 02 Oct 2017 19:04:47 +0000 Received: from homiemail-a24.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a24.g.dreamhost.com (Postfix) with ESMTP id 34E2C70F678B; Mon, 2 Oct 2017 12:04:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=cryptonector.com; h=date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=cryptonector.com; bh=uyVaTYznAjmbbw +ZvhYyPinxrGw=; b=YUdKSbshXkjYrBbxmRwPiWfJwODo1rXyTTmBc6CCcbgMwh BLnKPmPGUIFXMYO45I4978kD7koK81sGfYg1mJt68cHjDVtr0SL3TNkW1PDRjhDP Yc7bQzyTDiEBaaFpK+CfE5lYU/U7uab/Ic1asol+FbxgUSSFP/U3E/CCTq4lA= Received: from localhost (cpe-70-123-158-140.austin.res.rr.com [70.123.158.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: nico@cryptonector.com) by homiemail-a24.g.dreamhost.com (Postfix) with ESMTPSA id 8BF2F70F6788; Mon, 2 Oct 2017 12:04:40 -0700 (PDT) Date: Mon, 2 Oct 2017 14:04:38 -0500 From: Nico Williams To: Tom Lane Cc: Adam Brusselback , pgsql-hackers Subject: Re: generated columns Message-ID: <20171002190437.GK1251@localhost> References: <20171002152338.GH1251@localhost> <20171002181042.GI1251@localhost> <10550.1506969038@sss.pgh.pa.us> <20171002184641.GJ1251@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171002184641.GJ1251@localhost> User-Agent: Mutt/1.5.24 (2015-08-30) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org So yes, distinguishing stored vs. not stored computed columns is useful, especially if the expression can refer to other columns of the same row, though not only then. Examples: -- useful only if stored (assuming these never get updated) inserted_at TIMESTAMP WITHOUT TIME ZONE AS (clock_timestamp()) -- useful only if stored uuid uuid AS (uuid_generate_v4()) -- useful only if stored who_done_it TEXT (current_user) -- useful especially if not stored user_at_host TEXT (user || '@' || host) -- useful if stored original_user_at_host TEXT (user || '@' || host) I assume once set, a stored computed column cannot be updated, though maybe being able to allow this would be ok. Obviously all of this can be done with triggers and VIEWs... The most useful case is where a computed column is NOT stored, because it saves you having to have a table and a view, while support for the stored case merely saves you having to have triggers. Of course, triggers for computing columns are rather verbose, so not having to write those would be convenient. Similarly with RLS. RLS is not strictly necessary since VIEWs and TRIGGERs allow one to accomplish much the same results, but it's a lot of work to get that right, while RLS makes most policies very pithy. (RLS for *update* policies, however, still can't refer to NEW and OLD, so one still has to resort to triggers for updates in many cases). Nico -- -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers