Re: Script checking to see what database it's connected to

From: Julien Rouhaud <rjuju123(at)gmail(dot)com>
To: Ron <ronljohnsonjr(at)gmail(dot)com>
Cc: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Script checking to see what database it's connected to
Date: 2021-02-21 23:26:13
Message-ID: CAOBaU_ZeHj6FWJQiOMOKoxoe7DXLshoaCoLL0w1b3hpg++VJRQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Feb 22, 2021 at 7:19 AM Ron <ronljohnsonjr(at)gmail(dot)com> wrote:
>
> Thus, I want to add a bit to the top of the script, something like this:
>
> \if :DBNAME = postgres
> echo "must not run in postgres"
> exit
> \endif
>
> However, I can't seem to find the magic sauce.

You have to use a dedicated variable. Something like

SELECT :'DBNAME' = 'postgres' AS is_postgres \gset
\if :is_postgres
[...]

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rob Sargent 2021-02-21 23:26:54 Re: Script checking to see what database it's connected to
Previous Message Ron 2021-02-21 23:18:54 Script checking to see what database it's connected to