Search Postgresql Archives

Re: Determine server version from psql script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Igor Korot <ikorot01@xxxxxxxxx> writes:
> On Sat, Mar 22, 2025, 8:58 PM David G. Johnston <david.g.johnston@xxxxxxxxx>
> 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






[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux