Hi, Tom,
On Sat, Mar 22, 2025, 10:01 PM Tom Lane <t...@sss.pgh.pa.us> wrote: > Igor Korot <ikoro...@gmail.com> writes: > > On Sat, Mar 22, 2025, 8:58 PM David G. Johnston < > david.g.johns...@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 > 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 >