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 1twPHO-00E84c-4a for pgsql-general@arkaria.postgresql.org; Sun, 23 Mar 2025 17:38: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 1twPHM-002ZdC-Sr for pgsql-general@arkaria.postgresql.org; Sun, 23 Mar 2025 17:38: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 1twPHM-002Zd4-Dc for pgsql-general@lists.postgresql.org; Sun, 23 Mar 2025 17:38:32 +0000 Received: from mail-yw1-x1135.google.com ([2607:f8b0:4864:20::1135]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1twPHK-000i1e-2z for pgsql-general@lists.postgresql.org; Sun, 23 Mar 2025 17:38:31 +0000 Received: by mail-yw1-x1135.google.com with SMTP id 00721157ae682-6febbd3b75cso30279497b3.0 for ; Sun, 23 Mar 2025 10:38:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742751510; x=1743356310; 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=ILoKoHHTFClVjz20lcbkYSxga2tesifkbsCZYH9lbM8=; b=DEZQ/YjlUd9Br4zxsnQqqR6xK6ZeTkkj2qSlv+DiNw9/vdCLJ9af+uFzR/22JMBRNw l7kvkBYw1D502HJndbKcyJNi5Wx6MVy8nSE5amXahHYmBA31Ls4YC7oIgNZvxNMP0woO 3blI0bzwDGoxL6gWJSvXOlLz3aqjvGTVEnmUprAO6y9l+/zuEJHoaU2OkiFQ1CPHKBIK S7gPFQoSmmAvbQIwS1YuEZxiS2f1SOct2xjP6rN3fomshD0S46sohBTWUzBdrvVlIXoH NyRuIETS6XnqU/+UkidC3eqj7cLGoP74Ph5Dohzf2e6YgLDofWW1LnK6Q9xL4Z2e1zCt K+Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742751510; x=1743356310; 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=ILoKoHHTFClVjz20lcbkYSxga2tesifkbsCZYH9lbM8=; b=ACDpFXzL6I2nVj74+uzfNoPmAfXrbfwn07v9BokC5HAgBO5+k723rS2HXOrkfEpupa xXl2HNrVs/FSletWfqu3y08GxEaHgZZbPYLqrReH+plqo/KohdZetie+KJygwRFy/E0j CDnGpGeUrrtD9tINre5QXn6/AW/e9OEtQUVObceMwm+PgrlTnuFeqbF60TomaNeN6j4x sPa7jBEPWxlodU2tXOI0iYi8BRMOpMaAy/qRJztQmzN6JVDUHyqsbDVBMTHZ1BMg/X+b ZaJ++C1asGeKEh9hpOC+LJ+DTPeusLH3v5FGee/CZlARgDmeE2+DejkVSZc9Pzs3E5Nw HNMw== X-Forwarded-Encrypted: i=1; AJvYcCULiXkasKHxNo59/WLiQavb2Nd8dQmBFvFQY7M9NPajrMhXowjADdM4j0H4ZnrcxHYB4SH31QQvqT5Tll3T@lists.postgresql.org X-Gm-Message-State: AOJu0YxkHCl//0of1v4HISRyhHFzoHPMhLtcHo9NSr+qXEmRjsmv2ec/ FyfR11b3cDdxtaiEDYhTlJuXo8wLvR9bOBtj+keITDA5McHcVLaVci1CsBjSZyds6VXJT8+zQJw g2RCsoWlKLrai3Ph3V6ttEzM4EfU= X-Gm-Gg: ASbGncvHZR0ugmdBu9xeETgA87grYEhTMkGooJQjEY8y6NO4/6RmCBLEK7KQ44F8D3A hIltx9ACxAZvYYL7ib2i2hLwL0YwlljZu7yYIiDEFjPzuw3vCT14Js9wkwNWZ9P2b1E0HaRs0eb euVkd+jkAw5zsMCBHYzWn5wZ8ANgMb4QX2O+ONezk4KsT2bxf9NQIXbeUfbMI7 X-Google-Smtp-Source: AGHT+IFUqi53/fHcMVNAqi+vAtbqsiXRm+cdXTgQBDrgLiqQ7HbSWSqwFopExXseqmzu1V6AVhgm5rspvQsfRb2S5F4= X-Received: by 2002:a05:690c:3393:b0:6f9:871e:6903 with SMTP id 00721157ae682-700bad24c17mr148452717b3.37.1742751510059; Sun, 23 Mar 2025 10:38:30 -0700 (PDT) MIME-Version: 1.0 References: <90741d5f-5cda-4c4a-84f4-c470129732f4@aklaver.com> <473602.1742698901@sss.pgh.pa.us> In-Reply-To: <473602.1742698901@sss.pgh.pa.us> From: Igor Korot Date: Sun, 23 Mar 2025 12:38:18 -0500 X-Gm-Features: AQ5f1JpNznPLSg_niHD19pKbNQt3AvazwjXfhm7K-UBU6sw_qt1xK9a5ZawDsF0 Message-ID: Subject: Re: Determine server version from psql script To: Tom Lane Cc: "David G. Johnston" , Adrian Klaver , "pgsql-generallists.postgresql.org" Content-Type: multipart/alternative; boundary="000000000000b0610b063105f412" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000b0610b063105f412 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, Tom, On Sat, Mar 22, 2025, 10:01=E2=80=AFPM Tom Lane wrote: > Igor Korot writes: > > On Sat, Mar 22, 2025, 8:58=E2=80=AFPM David G. Johnston < > david.g.johnston@gmail.com> > > wrote: > >> Then read the psql docs. Your version has \if and you=E2=80=99ll find= server > >> version listed as the available client variables. > > > I was hoping for something like > > > If server_version >=3D X: > > CREATE OR REPLACE TRIGGER... > > psql's \if doesn't (yet) have any native expression evaluation > ability, so you have to farm out the ">=3D" comparison. The > psql docs suggest relying on the server to do it, which would > go along the lines of > > select current_setting('server_version_num')::int >=3D 130000 as v13 > \gset > \if :v13 > ... do something > \else > ... do something else > \endif > Thank for the code. 2 things, however. 1. Apparently CREATE OR RELACE TRIGGER syntax is available since v17, which is the current one. So I hadto adjust the numbers.. =F0=9F=98=80 2. Is there a way to do CREATE TRIGGER IF NOT EXIST for the earlier version= ? Thank you. > > You could also do the comparison client-side, along the lines of > > \set v13 `expr :SERVER_VERSION_NUM \>=3D 130000` > \if :v13 > ... etc > > But that introduces assorted platform dependencies and requires > close attention to correct shell quoting, so it's seldom > preferable IMO. > > regards, tom lane > --000000000000b0610b063105f412 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi, Tom,



On Sat, Mar 22, 2025, 10:01=E2=80=AFPM Tom Lane <tgl@sss.pgh.pa.us> wrote:
Igor Korot <ikorot01@gmail.com> writes:
> On Sat, Mar 22, 2025, 8:58=E2=80=AFPM David G. Johnston <da= vid.g.johnston@gmail.com>
> wrote:
>> Then read the psql docs.=C2=A0 Your version has \if and you=E2=80= =99ll find server
>> version listed as the available client variables.

> I was hoping for something like

> If server_version >=3D X:
>=C2=A0 =C2=A0 =C2=A0 CREATE OR REPLACE TRIGGER...

psql's \if doesn't (yet) have any native expression evaluation
ability, so you have to farm out the ">=3D" comparison.=C2=A0 = The
psql docs suggest relying on the server to do it, which would
go along the lines of

select current_setting('server_version_num')::int >=3D 130000 as= v13
\gset
\if :v13
=C2=A0 =C2=A0... do something
\else
=C2=A0 =C2=A0... do something else
\endif

Thank for the code.

2 things, however.
1. Apparently CREATE OR RELACE = TRIGGER syntax is available since v17, which is the current one. So I hadto= adjust the numbers.. =F0=9F=98=80
2. Is there a way= to do CREATE TRIGGER IF NOT EXIST for the earlier version?

Thank you.