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 1twQpN-00EYcT-84 for pgsql-general@arkaria.postgresql.org; Sun, 23 Mar 2025 19:17:45 +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 1twQpL-004Aqf-W8 for pgsql-general@arkaria.postgresql.org; Sun, 23 Mar 2025 19:17:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1twQpL-004AqX-Jy for pgsql-general@lists.postgresql.org; Sun, 23 Mar 2025 19:17:43 +0000 Received: from mail-yb1-xb2a.google.com ([2607:f8b0:4864:20::b2a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1twQpI-000iys-3A for pgsql-general@lists.postgresql.org; Sun, 23 Mar 2025 19:17:43 +0000 Received: by mail-yb1-xb2a.google.com with SMTP id 3f1490d57ef6-e634c42a296so2678424276.3 for ; Sun, 23 Mar 2025 12:17:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742757459; x=1743362259; 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=UZfN19cXhOkZrLgHxb2mreRIAUWYDdQZouA5RaOV8SQ=; b=QLV4oIvkoIV5FMys2RI91fCB7j+mXG2O0OFB2gU0YVkzJVymDrgxQcA1FKUYBdKa6t oCkpxyKU6ilzfpDnJoiww1gYeu2ab0jnkKcEu8ERR7SQGJKV7vG3Qe0QA/2CgdvqmJR5 ih+dr2HR0O30DbibhXpkSzG9eovWTXd3Eujd+ceVbXJCeUoWYfMg+opV68Dx+vx+LuAu KQhQzoeJp61fXR8UkfMPAJey1EpfZ/CvtgDx2Ad3mX7+G++4AicpXFpqVB+W7XkzveAR 2Ny78ege/FXt6xBibCtYWRlUrAAQl7otfBfT//8J1cswU6+7OOUWaj59J5z8jIAgoVZV 7how== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742757459; x=1743362259; 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=UZfN19cXhOkZrLgHxb2mreRIAUWYDdQZouA5RaOV8SQ=; b=HUA4ZavgeDFogZwXUkafOKMNI+TV3gz71Pd3KxWLiBxQbj2qUmpBGLuAhacM/0BSQ/ PBWBge/aDqJJb1NRXiZtF6tStLHGAP++6XJaxqZvUNkecdsh+WGKEJgmpNdAUV75aI3i vBibFMziNeXOYuuwlX+zhgpi7dctvzxNxyAp4XaUpSOYUiJo2Xg/dCP08BWs5YKz9xCI 56sej8QfeYKkOSSZugY7pDXJjxFGHTMNQ+2IHHUvV/esN+FskB16lx3gb5xBsKTJaSof Xa3+vzn5HI/Zz+1mowvqYp316VjjrqRFRoQ6eKWJW9xj7DRiIIzlq8i08qe4654+PzPs psIA== X-Forwarded-Encrypted: i=1; AJvYcCUUBLpeeztTCpUamj+gRSbF0Szp4pq6i0WPaUhv5VD24fd2TsQA7PFaSV4Voudx7O4rzadsKgQjHZonegYZ@lists.postgresql.org X-Gm-Message-State: AOJu0YytL0KwxmW6GKlPUp0wJ10F51uxoAoMOkJdlGjr7YwBEqVHr7FR LdOgrYIlEQzPMGlkqHZxFepNAIScQOPUjROPbm0DZ9xhiIwZnMBBo672xNiNR/bYZ6tKfzaRSk5 vKTfwCUy+m6E9Qb2Hb3x43JiEXzw= X-Gm-Gg: ASbGncv5467B+M/BJ11yeWVmulU5IQCizHiNSSjXCYiOfJm3/tNQvSk13ld9BLBt47h 1ERsNWyTawdlMCuM4e0hcoNBvhrGcoyzpZEHq+63rUyBWG4WFLu7FF5OvYLOGz+z42oWBKlAPYj HeBcDxfRtUDiVkf9uOf8cFkKKYgVWfAnn2XW7rBGFmrgK1hp/b+ne/t143+g8= X-Google-Smtp-Source: AGHT+IHvlKTcP+m40mBCB+StRxq1t92CPa9ruvouQu2xIVxpSh+LzQTuyVti6+DqK1pa6h/kcCAzjr+dIRZfnUuzNIo= X-Received: by 2002:a05:6902:1084:b0:e5d:c0db:b3de with SMTP id 3f1490d57ef6-e66a4f78ff5mr13095535276.34.1742757458824; Sun, 23 Mar 2025 12:17:38 -0700 (PDT) MIME-Version: 1.0 References: <90741d5f-5cda-4c4a-84f4-c470129732f4@aklaver.com> <473602.1742698901@sss.pgh.pa.us> In-Reply-To: From: Pavel Stehule Date: Sun, 23 Mar 2025 20:17:02 +0100 X-Gm-Features: AQ5f1Jq7Z-lnS9JHlLiItIsjpEh20mmdMQ5O5fxYhUlBVbDGBEd2n-UwTRlI8hE Message-ID: Subject: Re: Determine server version from psql script To: Igor Korot Cc: "David G. Johnston" , Tom Lane , Adrian Klaver , "pgsql-generallists.postgresql.org" Content-Type: multipart/alternative; boundary="000000000000435c36063107575b" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000435c36063107575b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi ne 23. 3. 2025 v 19:31 odes=C3=ADlatel Igor Korot naps= al: > Hi, > > [code] > SELECT current_setting('server_version_num')::int > 130000 as v13 > \gset > \if :v13 > CREATE OR REPLACE TRIGGER playersinleague_insert AFTER INSERT ON > playersinleague WHEN new.current_rank IS NULL > BEGIN > UPDATE playersinleague SET current_rank =3D 1 + (SELECT > coalesce( max( current_rank ), 0 ) FROM playersinleague WHERE id =3D > new.id) WHERE rowid =3D new.rowid; > psql:draft_pg.sql:44265: ERROR: syntax error at or near "TRIGGER" > LINE 1: CREATE OR REPLACE TRIGGER playersinleague_insert AFTER INSER... > ^ > [/code] > > What am I doing wrong? > the test should be SELECT current_setting('server_version_num')::int > =3D140000 as v14 \if :v14 ... CREATE OR REPLACE is supported from PostgreSQL 14 https://www.postgresql.org/docs/14/sql-createtrigger.html Regards Pavel > > Thank you. > > > On Sun, Mar 23, 2025 at 12:53=E2=80=AFPM David G. Johnston > wrote: > > > > On Sunday, March 23, 2025, David G. Johnston > wrote: > >> > >> On Sunday, March 23, 2025, Igor Korot wrote: > >>> > >>> > >>> 2. Is there a way to do CREATE TRIGGER IF NOT EXIST for the earlier > version? > >> > >> > >> No. You have to drop the trigger if it does exist and then create the > new one. > > > > > > Well, you can always query the catalogs directly to answer the question > =E2=80=9Cdoes this trigger exist=E2=80=9D. > > > > David J. > > > > > --000000000000435c36063107575b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi

ne 23. 3. 2025 v=C2=A019:31 o= des=C3=ADlatel Igor Korot <ikorot0= 1@gmail.com> napsal:
Hi,

[code]
SELECT current_setting('server_version_num')::int > 130000 as v1= 3
\gset
\if :v13
=C2=A0 =C2=A0CREATE OR REPLACE TRIGGER playersinleague_insert AFTER INSERT = ON
playersinleague WHEN new.current_rank IS NULL
=C2=A0 =C2=A0BEGIN
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0UPDATE playersinleague SET current= _rank =3D 1 + (SELECT
coalesce( max( current_rank ), 0 ) FROM playersinleague WHERE id =3D
new.id) = WHERE rowid =3D new.rowid;
psql:draft_pg.sql:44265: ERROR:=C2=A0 syntax error at or near "TRIGGER= "
LINE 1: CREATE OR REPLACE TRIGGER playersinleague_insert AFTER INSER...
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0^
[/code]

What am I doing wrong?


<= /div>
the test should be=C2=A0

SELECT current_= setting('server_version_num')::int > =3D140000 as v14
=
\if :v14
=C2=A0...

CREATE= OR REPLACE is supported from PostgreSQL 14


Regards

Pavel

Thank you.


On Sun, Mar 23, 2025 at 12:53=E2=80=AFPM David G. Johnston
<david.g= .johnston@gmail.com> wrote:
>
> On Sunday, March 23, 2025, David G. Johnston <david.g.johnston@gmail.com&g= t; wrote:
>>
>> On Sunday, March 23, 2025, Igor Korot <ikorot01@gmail.com> wrote:
>>>
>>>
>>> 2. Is there a way to do CREATE TRIGGER IF NOT EXIST for the ea= rlier version?
>>
>>
>> No.=C2=A0 You have to drop the trigger if it does exist and then c= reate the new one.
>
>
> Well, you can always query the catalogs directly to answer the questio= n =E2=80=9Cdoes this trigger exist=E2=80=9D.
>
> David J.
>


--000000000000435c36063107575b--