Re: Determine server version from psql script

2025-04-05 Thread Adrian Klaver
On 3/22/25 17:31, Igor Korot wrote: Hi, All, I have a big script that populated the DB for me. The language used for the script? Is it actually running in psql? I made it based on the latest available version. However,  i have version 13 installed on my Linux box and so trying to execute

Re: Determine server version from psql script

2025-04-04 Thread Adrian Klaver
On 3/23/25 10:38, Igor Korot wrote: Hi, Tom, 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.. 😀 Really?: https://www.postgresql.org/docs/14/sql-createtrigger.html "CREATE [ OR REPLACE ] [

Re: Determine server version from psql script

2025-03-28 Thread Igor Korot
Hi, [code] SELECT current_setting('server_version_num')::int > 13 as v13 \gset \if :v13 CREATE OR REPLACE TRIGGER playersinleague_insert AFTER INSERT ON playersinleague WHEN new.current_rank IS NULL BEGIN UPDATE playersinleague SET current_rank = 1 + (SELECT coalesce( max( cur

Re: Determine server version from psql script

2025-03-24 Thread David G. Johnston
On Sunday, March 23, 2025, Igor Korot wrote: > > 2. Is there a way to do CREATE TRIGGER IF NOT EXIST for the earlier > version? > No. You have to drop the trigger if it does exist and then create the new one. David J.

Re: Determine server version from psql script

2025-03-23 Thread David G. Johnston
On Sunday, March 23, 2025, David G. Johnston wrote: > On Sunday, March 23, 2025, Igor Korot wrote: > >> >> 2. Is there a way to do CREATE TRIGGER IF NOT EXIST for the earlier >> version? >> > > No. You have to drop the trigger if it does exist and then create the new > one. > Well, you can alw

Re: Determine server version from psql script

2025-03-23 Thread Pavel Stehule
Hi ne 23. 3. 2025 v 19:31 odesílatel Igor Korot napsal: > Hi, > > [code] > SELECT current_setting('server_version_num')::int > 13 as v13 > \gset > \if :v13 >CREATE OR REPLACE TRIGGER playersinleague_insert AFTER INSERT ON > playersinleague WHEN new.current_rank IS NULL >BEGIN >

Re: Determine server version from psql script

2025-03-23 Thread David G. Johnston
On Sunday, March 23, 2025, Igor Korot wrote: > > CREATE TRIGGER playersinleague_insert AFTER INSERT ON playersinleague > WHEN new.current_rank IS NULL > > When the syntax shows parentheses you are required to write them. [ WHEN ( *condition* ) ] David J.

Re: Determine server version from psql script

2025-03-23 Thread Igor Korot
Hi, Tom, On Sat, Mar 22, 2025, 10:01 PM Tom Lane wrote: > Igor Korot 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 va

Re: Determine server version from psql script

2025-03-23 Thread Christophe Pettus
> On Mar 23, 2025, at 18:08, Igor Korot wrote: > CREATE TRIGGER playersinleague_insert AFTER INSERT ON playersinleague > WHEN new.current_rank IS NULL The WHEN predicate has to be enclosed in parenthes: CREATE TRIGGER playersinleague_insert AFTER INSERT ON playersinleague WHEN (

Re: Determine server version from psql script

2025-03-23 Thread Igor Korot
Hi, This is what : [code[ \else DROP TRIGGER IF EXISTS playersinleague_insert ON playersinleague; CREATE TRIGGER playersinleague_insert AFTER INSERT ON playersinleague WHEN new.current_rank IS NULL BEGIN UPDATE playersinleague SET current_rank = 1 + (SELECT coalesce( max( curre

Re: Determine server version from psql script

2025-03-23 Thread David G. Johnston
On Sunday, March 23, 2025, Pavel Stehule wrote: > Hi > > ne 23. 3. 2025 v 19:31 odesílatel Igor Korot napsal: > >> Hi, >> >> [code] >> SELECT current_setting('server_version_num')::int > 13 as v13 >> > > SELECT current_setting('server_version_num')::int > =14 as v14 > IOW, you can’t us

Re: Determine server version from psql script

2025-03-22 Thread Tom Lane
Igor Korot writes: > On Sat, Mar 22, 2025, 8:58 PM David G. Johnston > 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 TRIGGE

Re: Determine server version from psql script

2025-03-22 Thread Igor Korot
Hi, David, On Sat, Mar 22, 2025, 8:58 PM David G. Johnston wrote: > On Saturday, March 22, 2025, Igor Korot wrote: > >> >> >>> Is it actually running in psql? >>> >> >> Yes, i run "psql - d draft -a -f >> > > Then read the psql docs. Your version has \if and you’ll find server > version liste

Re: Determine server version from psql script

2025-03-22 Thread David G. Johnston
On Saturday, March 22, 2025, Igor Korot wrote: > > >> Is it actually running in psql? >> > > Yes, i run "psql - d draft -a -f > Then read the psql docs. Your version has \if and you’ll find server version listed as the available client variables. David J.

Re: Determine server version from psql script

2025-03-22 Thread Igor Korot
Hi, Adrian, On Sat, Mar 22, 2025, 7:42 PM Adrian Klaver wrote: > On 3/22/25 17:31, Igor Korot wrote: > > Hi, All, > > I have a big script that populated the DB for me. > > The language used for the script? > What do you mean? Its just a text file with bunch of create table/insert into > Is it

Re: Determine server version from psql script

2025-03-22 Thread Tom Lane
Adrian Klaver writes: > On 3/22/25 17:31, Igor Korot wrote: >> Is there a way to determine the server version from such a script? > show server_version_num; psql already populates its SERVER_VERSION_NUM variable from that for you. regards, tom lane