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 1mpQQs-0006oo-Ob for pgsql-docs@arkaria.postgresql.org; Tue, 23 Nov 2021 07:41:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mpQQr-0007fK-B0 for pgsql-docs@arkaria.postgresql.org; Tue, 23 Nov 2021 07:41:37 +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 1mpET8-0001kW-OY for pgsql-docs@lists.postgresql.org; Mon, 22 Nov 2021 18:55:10 +0000 Received: from rmr1.rz.htw-dresden.de ([141.56.16.231]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mpET1-0003A8-Vi for pgsql-docs@lists.postgresql.org; Mon, 22 Nov 2021 18:55:09 +0000 Received: from localhost (localhost [127.0.0.1]) by rmr1.rz.htw-dresden.de (Postfix) with ESMTP id D93FA101B2; Mon, 22 Nov 2021 19:55:00 +0100 (CET) X-HTW-Virus-Scanned: Debian amavisd-new at rmr1.rz.htw-dresden.de Received: from rmr1.rz.htw-dresden.de ([127.0.0.1]) by localhost (rmr1.rz.htw-dresden.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cJxrdc9EaYz1; Mon, 22 Nov 2021 19:54:53 +0100 (CET) Received: from rmex21.dom.htw-dresden.de (rmex21.dom.htw-dresden.de [141.56.1.153]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "groupware.htw-dresden.de", Issuer "DFN-Verein Global Issuing CA" (verified OK)) by rmr1.rz.htw-dresden.de (Postfix) with ESMTPS id 8B6AC100C0; Mon, 22 Nov 2021 19:54:53 +0100 (CET) Received: from [192.168.178.10] (141.56.16.106) by rmex21.dom.htw-dresden.de (141.56.1.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.10; Mon, 22 Nov 2021 19:54:53 +0100 Subject: Re: Triggers on underlying tables of updatable views To: Laurenz Albe , References: <163758281947.26190.10251137266467665332@wrigleys.postgresql.org> <2f54dbb7d59aacacbc4654b0bc56faaebe993e09.camel@cybertec.at> From: Max Ziermann Message-ID: <3e14b477-40ce-4b6a-047a-9fea3843427c@htw-dresden.de> Date: Mon, 22 Nov 2021 19:54:52 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <2f54dbb7d59aacacbc4654b0bc56faaebe993e09.camel@cybertec.at> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Content-Language: de-DE X-Originating-IP: [141.56.16.106] X-ClientProxiedBy: rmex11.dom.htw-dresden.de (141.56.1.151) To rmex21.dom.htw-dresden.de (141.56.1.153) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Thanks for your reply. Maybe I am missing an obvious point, but I don't think that's the case. SQL example: CREATE ROLE view_access; CREATE TABLE data (a integer primary key); CREATE VIEW data_view AS SELECT * FROM data; GRANT SELECT, INSERT ON data_view TO view_access; CREATE FUNCTION trig() RETURNS trigger AS $$ BEGIN     RAISE NOTICE 'trig() executed as user=%', current_user;     PERFORM COUNT(*) FROM data;     RETURN new; END $$ LANGUAGE plpgsql; CREATE TRIGGER trig AFTER INSERT ON data FOR EACH ROW EXECUTE FUNCTION trig(); -- Executed by owner of view, data and trigger: (as expected) all ok INSERT INTO data_view VALUES (1); SET ROLE TO view_access; -- Executed by view_access: fails INSERT INTO data_view VALUES (2); For the second INSERT, the trigger is called by the user performing the insert instead of the user owning the table or the view. Best Regards, Max Ziermann Am 22.11.21 um 16:41 schrieb Laurenz Albe: > On Mon, 2021-11-22 at 12:06 +0000, PG Doc comments form wrote: >> "Note that the user performing the insert, update or delete on the view must >> have the corresponding insert, update or delete privilege on the view. In >> addition the view's owner must have the relevant privileges on the >> underlying base relations, but the user performing the update does not need >> any permissions on the underlying base relations (see Section 41.5)." >> >> Could it be made more clear that triggers on a underlying table of an >> updatable view are still executed with the permissions of the user >> performing an insert/update/delete on the view? > But that is not the case: that trigger will be executed with the permissions > of the owner of the underlying table. > > Yours, > Laurenz Albe >