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 1vBDJh-00Cr2T-64 for pgsql-general@arkaria.postgresql.org; Tue, 21 Oct 2025 14:26:24 +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 1vBDJf-009YVp-Va for pgsql-general@arkaria.postgresql.org; Tue, 21 Oct 2025 14:26:23 +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 1vBDJf-009YVh-HT for pgsql-general@lists.postgresql.org; Tue, 21 Oct 2025 14:26:22 +0000 Received: from mail-oa1-x2a.google.com ([2001:4860:4864:20::2a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vBDJc-002zf9-2k for pgsql-general@lists.postgresql.org; Tue, 21 Oct 2025 14:26:21 +0000 Received: by mail-oa1-x2a.google.com with SMTP id 586e51a60fabf-3c92328d0bcso2909917fac.2 for ; Tue, 21 Oct 2025 07:26:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761056775; x=1761661575; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=SoLWjpyYcQ2ck5mbzwLpyi2QMo1rBUvpqOXxNMPeRT0=; b=MV0UGKX3er3AZ5WzR+z14OtDm/SdGYkxsbh5z8IQC407sJ9We6JVkclRCtGQhqQ1at iptzQll9/7lTutH9qp9LoVEHqWq3yybp5F/Dd8fQkejaKS1ZQOl6ybxf2QCV2bT/HyuA 5hlkZitPOMdvheC2gxveCXcGZnxx71pMySYvYx1T/0q0mqh/j/2gCFVcMorx+DQCQcER qoHbXDpECPLu882psmULDORZWx0wzXjh/O6Ulbzg7mNqNplxm9iE86v0i/H5zzN7QCbN SW3LirMjhoDyXIWWhL/grsOj79TRba4E3alTYYZK/lPf7BSf1JF2zdW1i8N7wrbYx4hO YulA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761056775; x=1761661575; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SoLWjpyYcQ2ck5mbzwLpyi2QMo1rBUvpqOXxNMPeRT0=; b=BRPHS2VW3nH253/5nTiYR5bokxE/ORJ3Lz0gHflDwIAxqMFeb55YRkdPIMk5eDV3pq OP7WDTjJ1JvIBnE8Wj0gjY+ZgC2Gpbp3BjRVSBYeZPQKoESkFWjyAnV+T/SBDSed1NuJ mqsLPrwyXayGsXo9O7JiVFKwHxRSDdnUMSazj1y4ORHApcyjV8gIl7x8ItoqA5uCqYAl Os9/NjoLPf/EhLBmgxBejUeqA1AXziWe+AMXfMQa7eWadKQ1RQFwU+CwSxWm2rBeay1O 4ey0lZ/Pr5dMoeZOvlmrQE0Vmi5Zj6u6uOM5btG1sudu/8K3NOfRqXt8VXSu+Ga4mOg0 iOQQ== X-Forwarded-Encrypted: i=1; AJvYcCWOTGZhL8n3+g5lm+YwwC98HS+OF6dODH7z4o4Ne01TBx/0IVP6GMCFzs1GD6KjQCJaT4XutL2Rr4gFWARD@lists.postgresql.org X-Gm-Message-State: AOJu0YwcXPp5UfNnyJPkL9dU7nAUP9ZRWEvy2t0OUOxZgt0WyhtTo2QP KYRr4wnVXQHm/GCWcoO4OnxOS9V10MFmK1jDAy9Ew7EBR54H/XTuEQ5VFS8Smmx43Z//2Tv1RdP r+NxcRf9IK5+8/ErDOZ2HFCNC0/FjP40= X-Gm-Gg: ASbGncs6h8Bto5WTpJ4RrDIjJrN5JZNr6aSTryi6G72DaLD59BOSNTjVnpcYd46QoYC NpFf2meZRMv06Hg4jaJUdbTU4pYBCLz6Xz2g/tVyOYmPByl1plnGygRl75hPFNlzP5Twj+R5oZb HINOhTEegmMhU5WghcPJG1nSW06XknvNkZ49OvrCirO+kVqr8mwoqwGOkV64qwpePngoe+77STA uyyxiDtrnMDZidlnYFdAfA1hhI22favNKXLrED/2y3l1eX475OTAW8bHosFUX2kiGRJmrWv X-Google-Smtp-Source: AGHT+IEoQqxKeTFBUJPpYXQJvWyPqPyGZSzfthgunqRU8DUYBZ13SjFkcKXYrvv6UyJxhuYBUEl/d0lGVr3c0GslmLo= X-Received: by 2002:a05:6870:8194:b0:2ff:9776:1231 with SMTP id 586e51a60fabf-3c98cf25436mr6226371fac.1.1761056775255; Tue, 21 Oct 2025 07:26:15 -0700 (PDT) MIME-Version: 1.0 References: <202510210716.4cr5qkq2z2mj@alvherre.pgsql> In-Reply-To: From: Ron Johnson Date: Tue, 21 Oct 2025 10:26:04 -0400 X-Gm-Features: AS18NWDXFZNdfUxOH94Q3PCZcbroQ3K7QYVzfLoSeoYd8Osr3ubxt59o2PAP91A Message-ID: Subject: Re: Extend CREATE POLICY to add IF EXISTS To: Paul Austin Cc: =?UTF-8?Q?=C3=81lvaro_Herrera?= , "pgsql-general@lists.postgresql.org" Content-Type: multipart/alternative; boundary="00000000000084baa60641abfb9a" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000084baa60641abfb9a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Doesn't CREATE OR REPLACE have limitations based on parameter-list changes? On Tue, Oct 21, 2025 at 10:08=E2=80=AFAM Paul Austin wrote: > =C3=81lvaro, > > Yes, a CREATE OR REPLACE would also be useful. > > However, the CREATE IF NOT EXISTS is also useful when you aren't concerne= d > that the POLICY is going to change. Same with the existing CREATE TABLE I= F > NOT EXISTS. > > Yes I'm aware that the DROP/CREATE can create a security hole, which is > why I'd like the IF NOT EXISTS. At the moment my use case stops the > application prior to running this script and the database is in a private > network. > > -----Original Message----- > From: =C3=81lvaro Herrera > Sent: October 21, 2025 12:23 AM > To: Paul Austin > Cc: pgsql-general@lists.postgresql.org > Subject: Re: Extend CREATE POLICY to add IF EXISTS > > 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. > > -- > =C3=81lvaro Herrera Breisgau, Deutschland =E2=80=94 > https://www.EnterpriseDB.com/ > "I love the Postgres community. It's all about doing things _properly_. > :-)" > (David Garamond) > --=20 Death to , and butter sauce. Don't boil me, I'm still alive. lobster! --00000000000084baa60641abfb9a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Doesn't CREATE OR REPLACE have limitations based = on=C2=A0parameter-list changes?

On Tue, Oct 21, 2025 a= t 10:08=E2=80=AFAM Paul Austin <paul.austin@automutatio.com> wrote:
=C3=81lvaro,

Yes, a CREATE OR REPLACE would also be useful.

However, the CREATE IF NOT EXISTS is also useful when you aren't concer= ned that the POLICY is going to change. Same with the existing CREATE TABLE= IF NOT EXISTS.

Yes I'm aware that the DROP/CREATE can create a security hole, which is= why I'd like the IF NOT EXISTS. At the moment my use case stops the ap= plication prior to running this script and the database is in a private net= work.

-----Original Message-----
From: =C3=81lvaro Herrera <alvherre@kurilemu.de>
Sent: October 21, 2025 12:23 AM
To: Paul Austin <paul.austin@automutatio.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Extend CREATE POLICY to add IF EXISTS

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 <= br> > don't need to do a drop and create.

How would CREATE IF NOT EXISTS handle the case of an existing policy that d= oesn't match the one you want?=C2=A0 I think it would just silently not= do anything, and in that case you can't really rely on it, can you?=C2= =A0 So your script would have to extract the current policy, compare with t= he one you want (how?) and then maybe drop it and create it anew, or leave = it alone.=C2=A0 Is this really useful?

I think what you'd really appreciate is CREATE OR REPLACE: if the polic= y exists and matches the one you ask for, then don't do anything; but o= therwise throw it away and create it anew.=C2=A0 We have this for views, an= d 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 exis= ts a period in between where no policy exists, which could be a security ho= le.=C2=A0 Unless you use an explicit transaction block.

--
=C3=81lvaro Herrera=C2=A0 =C2=A0 =C2=A0 =C2=A0 Breisgau, Deutschland=C2=A0 = =E2=80=94=C2=A0 https://www.EnterpriseDB.com/
"I love the Postgres community. It's all about doing things _prope= rly_. :-)"
(David Garamond)


--
Death to <Redacted>, and butter sauce.Don't boil me, I'm still alive.
<Redacted> lobs= ter!
--00000000000084baa60641abfb9a--