Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fRHQf-0006pR-10 for pgsql-general@arkaria.postgresql.org; Fri, 08 Jun 2018 13:27:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fRHQd-0000Rn-Ry for pgsql-general@arkaria.postgresql.org; Fri, 08 Jun 2018 13:27:43 +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.89) (envelope-from ) id 1fRHQc-0000Rc-4V for pgsql-general@lists.postgresql.org; Fri, 08 Jun 2018 13:27:43 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fRHQS-0001tp-JN for pgsql-general@postgresql.org; Fri, 08 Jun 2018 13:27:41 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 281B321B42; Fri, 8 Jun 2018 09:27:30 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 08 Jun 2018 09:27:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=zi+Z+isDUDpK3ArCUdDs7OXYahilG UvKhmu9ngMNU5E=; b=CpIN9vnsjiyuhUO+cBbpYdKjFGjDdAqfK1CTd/dT8hfTd 7qqIy7pYfFYVd+tVAVTX6CtGB7DJN8FMG52KVARkuaGZsubY0a0b7CjJP3zvAaxM 68dRz/Mlt4rMWr89GPI3W47oUoppVp6jysBZeQULQUSZex47LjZsbIWhpP/NpGFN BQV3w+Mzky93tR3k7q3Ox3lCEp5JJQqFuM8jFXPRe9AU4ZGFCnAhqmLmCQtOljJo JYvq1hdsKp0ydMpiYhxqgAWG6PVgA16vyNEJf+Hc1HWNC2TP5XgqJRK93XmlWjI7 wx9cVWmdGR/Ry7SiWg1GxZDKq/aeEy/MctYEzXvAQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=zi+Z+i sDUDpK3ArCUdDs7OXYahilGUvKhmu9ngMNU5E=; b=DCi8vuQq80ipp09784JGFB E13RdNwZFelSkPJjN+Vodk9kHOO/Qe4mvNGeLgWNyDDplA2Q4hSnGbHXicyKAsNs Nb6eGt4vCQjItCU1LGF84znJlOiQtSoy62ydSlcKPfrzTDA6CKukTsWthWtuP2kp ctExDFzfOwjGeelV1anMow7vQM7eS/fRxH2gZ+HHX+OC0VzhbPkbxJ7ZUkS6y416 EphkidYTar1cB42NZpTqJFUUT0lSoNU1gITpLIRyMrXAiIW4cFTbwOizuXfzbO// 0Rdjxy3+Fm7N3n1BcSrKuKf4uFYgEd4TCr6SeOU+SVE3DuVqq/+acqmDKOcic48g == X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Sender: Received: from [192.168.1.3] (unknown [71.212.159.209]) by mail.messagingengine.com (Postfix) with ESMTPA id 5853CE47A0; Fri, 8 Jun 2018 09:27:29 -0400 (EDT) Subject: Re: Can you make a simple view non-updatable? To: Ryan Murphy , pgsql-general References: From: Adrian Klaver Message-ID: <1cc0d88c-52f5-e4a0-cf21-ab5e645a90e1@aklaver.com> Date: Fri, 8 Jun 2018 06:27:28 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 06/08/2018 01:38 AM, Ryan Murphy wrote: > Hello. > > I enjoy using VIEWs.  Often my views are updatable, either automatically > (due to being a simple 1-table view, or due to a TRIGGER).  Sometimes > they are meant to be just read-only. > > Is there any way to set a VIEW to be read-only -- specifically, can I do > this for a view that is automatically updatable due to being simple? Using INSTEAD OF trigger?: create view ct_vw as select * from container; insert into ct_vw (c_id, cdesc, cell_per, c_size, c_units) values ('test', 'test container', 1, 2, 4); INSERT 1836533 1 CREATE OR REPLACE FUNCTION public.vw_ro() RETURNS trigger LANGUAGE plpgsql AS $function$ BEGIN RAISE NOTICE 'Read only view'; RETURN NULL; END; $function$ CREATE TRIGGER ro_trg INSTEAD OF INSERT or UPDATE or DELETE ON ct_vw FOR EACH ROW EXECUTE procedure vw_ro(); insert into ct_vw (c_id, cdesc, cell_per, c_size, c_units) values ('test', 'test container', 1, 2, 4); NOTICE: Read only view INSERT 0 0 update ct_vw set cell_per = 100 where c_id = '200PT'; NOTICE: Read only view UPDATE 0 delete from ct_vw where c_id = '200PT'; NOTICE: Read only view DELETE 0 > > The reason I want this:  It will help me encode into my schema the > distinction between views that are supposed to behave like full-fledged > "subtypes" of a larger relation and need to be updatable, vs those that > are merely a report / literally just a "view". > > Thanks! > Ryan -- Adrian Klaver adrian.klaver@aklaver.com