From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Igor Korot <ikorot01(at)gmail(dot)com> |
Cc: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Determine server version from psql script |
Date: | 2025-03-23 03:01:41 |
Message-ID: | 473602.1742698901@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Igor Korot <ikorot01(at)gmail(dot)com> writes:
> On Sat, Mar 22, 2025, 8:58 PM David G. Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
> wrote:
>> Then read the psql docs. Your version has \if and you’ll find server
>> version listed as the available client variables.
> I was hoping for something like
> If server_version >= X:
> CREATE OR REPLACE TRIGGER...
psql's \if doesn't (yet) have any native expression evaluation
ability, so you have to farm out the ">=" 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 >= 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 \>= 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
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Paquier | 2025-03-23 06:38:10 | Re: query_id: jumble names of temp tables for better pg_stat_statement UX |
Previous Message | Igor Korot | 2025-03-23 02:28:14 | Re: Determine server version from psql script |