public inbox for [email protected]
help / color / mirror / Atom feedFrom: Igor Korot <[email protected]>
To: Tom Lane <[email protected]>
Cc: David G. Johnston <[email protected]>
Cc: Adrian Klaver <[email protected]>
Cc: pgsql-generallists.postgresql.org <[email protected]>
Subject: Re: Determine server version from psql script
Date: Sun, 23 Mar 2025 12:38:18 -0500
Message-ID: <CA+FnnTztyXpMxEiKTZhxMtcQ8Nm6D+M1jbfJFfkJYU9dyvTeLg@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <CA+FnnTyWEsYi=_QTeSXoGXd7Fkd8C7_AnCc5=hho-DZF9_iunQ@mail.gmail.com>
<[email protected]>
<CA+FnnTz9-cjBDf3mC9fx_FCtZGDTneF9=w8LpTRdwCfxHN86yw@mail.gmail.com>
<CAKFQuwZGjMYbP0nWYb2+-D1a_dNg6b-mDhDC96Am-c2MZOYTNw@mail.gmail.com>
<CA+FnnTy2Lk+K8t2uKwc1cAnCm6+RTb72eVRxt9+Y8y+C=sUeyA@mail.gmail.com>
<[email protected]>
Hi, Tom,
On Sat, Mar 22, 2025, 10:01 PM Tom Lane <[email protected]> wrote:
> Igor Korot <[email protected]> writes:
> > On Sat, Mar 22, 2025, 8:58 PM David G. Johnston <
> [email protected]>
> > 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
>
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.. 😀
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 \>= 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
>
view thread (14+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: Re: Determine server version from psql script
In-Reply-To: <CA+FnnTztyXpMxEiKTZhxMtcQ8Nm6D+M1jbfJFfkJYU9dyvTeLg@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox