Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vB6iU-00Aosi-PL for pgsql-general@arkaria.postgresql.org; Tue, 21 Oct 2025 07:23:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1vB6iT-007NJL-Nb for pgsql-general@arkaria.postgresql.org; Tue, 21 Oct 2025 07:23:32 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vB6iT-007NJ5-81 for pgsql-general@lists.postgresql.org; Tue, 21 Oct 2025 07:23:32 +0000 Received: from fhigh-a6-smtp.messagingengine.com ([103.168.172.157]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1vB6iQ-002wJm-24 for pgsql-general@lists.postgresql.org; Tue, 21 Oct 2025 07:23:31 +0000 Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfhigh.phl.internal (Postfix) with ESMTP id 4A9EF1400037; Tue, 21 Oct 2025 03:23:30 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Tue, 21 Oct 2025 03:23:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kurilemu.de; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to; s=fm1; t=1761031410; x= 1761117810; bh=+euKaUL402U9wueRELblX0BcohYhKCnVeyvcAakXGq8=; b=k NnxCCpAAZnWJ9oRpWSQxwdzWd7VCIkrrpRtlKmw7RkGKXBdIC1S8f1GJNpCdcFzG u2aWOTJJ8WLsnKKpLsD7YBUxVyhBzVMdiMALxLzxFUTL27GNvuFDvV0S339UmJHW xCrer7N+ao7UElHFpjdyCk3Q9cMTfR2xzNEStPy7W/lKLEO7LsLQml9YZAsrgDRE eefjkRNZSnYl8gEWXKjllLMtsJICaD9x1LJRkqghON1NyEEWyF/syb0IV4SSaxr1 0ASQp0sn9JfEw5DBFpGGaPJN9bNUsAhO78fL5fIAMKwW5ZPFpgob4VTnmK3fHMCZ x3pSL+fpiZeAKdshup20g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1761031410; x=1761117810; bh=+ euKaUL402U9wueRELblX0BcohYhKCnVeyvcAakXGq8=; b=Z1qNtQMuUVlFMIAvB flN76c3onsCh9vtWH+jcrVxJEZsARalaAvuJIza665MFNstMaWhK+9I/qmWg9hvV YBaTAhIGT3MNa36seI5JndfvfjT4N1mZlQ3031pbOraWC6nKqjujxzQGpFZxAh3U dNMxghwJQU6JUAMC6Gxs+bGxfTZynVk6rEwYbeGCroC+vgnmmzHB9fUbI0lfEylq WYoo2kPjljxML7V6uomBlKjsbo06Zm0m0Hyjfs9N4XcPBiusgzE5KSwmOHoe/Uv4 g6cx6Xc8cqtAaIc6cZDKKxk3zn+iI2rQvBi2okvtEYkPc6C8hSSSlorax/FtPOUy q4okw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddugedttdelucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepfffhvfevuffkgggtugfgjgesthekredttddtjeenucfhrhhomheplmhlvhgrrhho ucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsehkuhhrihhlvghmuhdruggvqeenucggtf frrghtthgvrhhnpeetuedvheffkeevgfeuheevteevkefggedttdeufeeuheduuddthfef fffhjeefffenucffohhmrghinhepvghnthgvrhhprhhishgvuggsrdgtohhmnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghlvhhhvghrrhgv sehkuhhrihhlvghmuhdruggvpdhnsggprhgtphhtthhopedvpdhmohguvgepshhmthhpoh huthdprhgtphhtthhopehprghulhdrrghushhtihhnsegruhhtohhmuhhtrghtihhordgt ohhmpdhrtghpthhtohepphhgshhqlhdqghgvnhgvrhgrlheslhhishhtshdrphhoshhtgh hrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: ie3de48e3:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 21 Oct 2025 03:23:29 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kurilemu.de; s=schmee; t=1761031407; bh=GPgXGev9IkllNmEdS+gRFnEp/vfoFJjrVcjxlD31Pbw=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=9XskmJyvgqYsHKp8Jg3BCovzGY9F9ns1ppucwEYpC7TQ8HdGeHfmmbe1XpE/Fb7HU 9odKwioUSmNcdfWPWbGLwr94oR2i9PpnEwMco+PP4bYCPXfxC+oM9Mx2rxDx0iYTTb G0mNdQK+dxPADA0HpTYI1Tk1Ir+nzmYukWsxW0HbfYBfVcnQzNloUO1Y1Q68K9OEz/ CWF3YF52PWJGRz1oGyMjcj4kyXfcYzSLx3+YY2KYJscLNSdTUNPfbbmMKCbMbSkv97 T948fFGZFG2nCcJm3dw58/nqLMuUGjbkyaoo1V4c+Mla73loW8sDcKNDFkCj8/fy7S rreoIsmHIRe3w== Received: by schmee.kurilemu.internal (Postfix, from userid 1000) id D47A36A; Tue, 21 Oct 2025 09:23:27 +0200 (CEST) Date: Tue, 21 Oct 2025 10:23:27 +0300 From: =?utf-8?Q?=C3=81lvaro?= Herrera To: Paul Austin Cc: "pgsql-general@lists.postgresql.org" Subject: Re: Extend CREATE POLICY to add IF EXISTS Message-ID: <202510210716.4cr5qkq2z2mj@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2025-Oct-20, Paul Austin wrote: > Adrian, > > The drop policy IF EXISTS does work. > > But it would be nice to have the IF NOT EXISTS on CREATE POLICY so I > don't need to do a drop and create. How would CREATE IF NOT EXISTS handle the case of an existing policy that doesn't match the one you want? I think it would just silently not do anything, and in that case you can't really rely on it, can you? So your script would have to extract the current policy, compare with the one you want (how?) and then maybe drop it and create it anew, or leave it alone. Is this really useful? I think what you'd really appreciate is CREATE OR REPLACE: if the policy exists and matches the one you ask for, then don't do anything; but otherwise throw it away and create it anew. We have this for views, and it allows for things like adding more columns than the original view had. BTW, the pattern DROP IF EXISTS / CREATE is a bit nasty, because there exists a period in between where no policy exists, which could be a security hole. Unless you use an explicit transaction block. -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/ "I love the Postgres community. It's all about doing things _properly_. :-)" (David Garamond)