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 1twBaw-00BXND-D2 for pgsql-general@arkaria.postgresql.org; Sun, 23 Mar 2025 03:01:50 +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 1twBat-0081fw-CE for pgsql-general@arkaria.postgresql.org; Sun, 23 Mar 2025 03:01:47 +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 1twBat-0081fn-1Y for pgsql-general@lists.postgresql.org; Sun, 23 Mar 2025 03:01:47 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1twBar-000bdN-0g for pgsql-general@lists.postgresql.org; Sun, 23 Mar 2025 03:01:46 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 52N31fs0473603; Sat, 22 Mar 2025 23:01:41 -0400 From: Tom Lane To: Igor Korot cc: "David G. Johnston" , Adrian Klaver , "pgsql-generallists.postgresql.org" Subject: Re: Determine server version from psql script In-reply-to: References: <90741d5f-5cda-4c4a-84f4-c470129732f4@aklaver.com> Comments: In-reply-to Igor Korot message dated "Sat, 22 Mar 2025 21:28:14 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <473601.1742698901.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 22 Mar 2025 23:01:41 -0400 Message-ID: <473602.1742698901@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Igor Korot writes: > On Sat, Mar 22, 2025, 8:58=E2=80=AFPM David G. Johnston > 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 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