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 1mpT2E-0001oF-J0 for pgsql-docs@arkaria.postgresql.org; Tue, 23 Nov 2021 10:28:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mpT2C-0006o7-T5 for pgsql-docs@arkaria.postgresql.org; Tue, 23 Nov 2021 10:28:20 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mpT2C-0006ny-A9 for pgsql-docs@lists.postgresql.org; Tue, 23 Nov 2021 10:28:20 +0000 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mpT25-00004s-U1 for pgsql-docs@lists.postgresql.org; Tue, 23 Nov 2021 10:28:19 +0000 Received: by mail-wr1-x430.google.com with SMTP id c4so38027672wrd.9 for ; Tue, 23 Nov 2021 02:28:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20210112.gappssmtp.com; s=20210112; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=wHiLR3VFlrLtQn7X7wOZ8Ji/1rOCrx/oxxapkVLsFZY=; b=HJmeqqu8zZ2OWeRwx9BmCuGNyV0q/+BzMQcU3M0DfvWimOE1njYJx1jF1Rq9RdSSOd 7nP0JJv4KfpKq5VllNFNvHDSYTGSeYyoHrnkWMF+H7LChdEHGOXN1xdoWXPFOoz/U7fk zNgk89e0WbtXWFS/RO316Ei6MqD4417BzsJQOVFkV0OVTyhMjP/KFsnZIUHV4dtL333U /v5/xKhLMENy4gLyuaKiJdOt+eCasqXuGlchAd+qiWypg1C2snfr7FjtbHiFIh+mAS6v S4jQ+OcKxYeT8qm9DQ8sPMbbHGc1k/vWTc/9BhIVAk8N6GaI2rTpAq7ESewOusgfOiYp oRpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=wHiLR3VFlrLtQn7X7wOZ8Ji/1rOCrx/oxxapkVLsFZY=; b=vDX3kNjszNCXjwf/HTdEz0uDZMrn0FfRq/dFcjqQxzxZL7GWwYj2Qrvm+D4+GNzuPE bTxJRkh9hk2sbcJM4sSeXimaOtMOqWrQyMjeANS81jYoXtK2M5Po6sc7zrkhbwjVb75g f03yT9N7PoEXRdbpd/qYOlmDd8gv/lPbAjKnrfwpBaWoQiCewcfZ8sq8U78uZso7WkGu aqfScpGp/tqeFWNYfkcjk0P5Unx704j/mKXOquWcnpMe1EQfz6X0H3zLgXLyVmKgdKGj iaZ8QliRjZWnZL6elcoZ9oaEohayEMrqRy9LCAIOP+tT2LJo1UspWkZvs6WsZL7IRoXJ JTeg== X-Gm-Message-State: AOAM530IrzHIJ4u4YxjPyoZrF5lkJNCtSNNCGWMYWW6K0Clnz6IWCkLj v7PZFGtakIuOsgZATNsgl084wun5HrMddw== X-Google-Smtp-Source: ABdhPJzQJ6RW95cXIDBm2ykZ8fD+9EQZq8FNKmbPZVX+2X04/ZwvpyR/S4X3SMudweEL8keR3A7bYw== X-Received: by 2002:adf:82f7:: with SMTP id 110mr6141057wrc.111.1637663292558; Tue, 23 Nov 2021 02:28:12 -0800 (PST) Received: from localhost.localdomain (dynamic-ectchcg50ofk8ie0k-pd01.res.v6.highway.a1.net. [2001:871:5e:824d:3750:fe9d:6eaa:df74]) by smtp.gmail.com with ESMTPSA id l22sm622949wmp.34.2021.11.23.02.28.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 02:28:12 -0800 (PST) Message-ID: Subject: Re: Triggers on underlying tables of updatable views From: Laurenz Albe To: Max Ziermann , pgsql-docs@lists.postgresql.org Date: Tue, 23 Nov 2021 11:28:11 +0100 In-Reply-To: References: <163758281947.26190.10251137266467665332@wrigleys.postgresql.org> <2f54dbb7d59aacacbc4654b0bc56faaebe993e09.camel@cybertec.at> <3e14b477-40ce-4b6a-047a-9fea3843427c@htw-dresden.de> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.4 (3.40.4-2.fc34) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 2021-11-22 at 21:02 +0100, Laurenz Albe wrote: > On Mon, 2021-11-22 at 19:54 +0100, Max Ziermann wrote: > > 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. > > > > Maybe I am missing an obvious point, but I don't think that's the case. > > SQL example: After some more thinking and experimenting, I realize that was wrong. The trigger will always execute with the permissions of the user running the query. Only the permissions on the underlying tables are checked for the view owner, the actual query is executed in the security context of the user that queries the view. I don't think that requires special mention on the CREATE VIEW page, since it is no different when views are not involved. It might be worth mentioning on https://www.postgresql.org/docs/current/trigger-definition.html that triggers (unless the function is SECURITY DEFINER) are executed under the security context of the user that runs the query, rather than under the security context of the table owner. Yours, Laurenz Albe