Re: Determine server version from psql script
| От | Tom Lane |
|---|---|
| Тема | Re: Determine server version from psql script |
| Дата | |
| Msg-id | 473602.1742698901@sss.pgh.pa.us обсуждение |
| Ответ на | Re: Determine server version from psql script (Igor Korot <ikorot01@gmail.com>) |
| Ответы |
Re: Determine server version from psql script
|
| Список | pgsql-general |
Igor Korot <ikorot01@gmail.com> writes:
> On Sat, Mar 22, 2025, 8:58 PM David G. Johnston <david.g.johnston@gmail.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
В списке pgsql-general по дате отправления: