Search Postgresql Archives

Script checking to see what database it's connected to

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Postgresql 12.5

I've got scripts which can run on multiple database (dev, test, QA, Integration, Training, etc, etc), so of course I've got to run them like "psql my_db_name -f script.sql".

Of course, I sometimes forget to specify the database name, and so it fails.

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.

This is what I've tried so far:

postgres=# \if :DBNAME == postgres
unrecognized value "postgres == postgres" for "\if expression": Boolean expected
postgres@#

postgres=# \if ':DBNAME' == postgres
unrecognized value ":DBNAME == postgres" for "\if expression": Boolean expected
postgres@#

postgres=# \if :DBNAME == 'postgres'
unrecognized value "postgres == postgres" for "\if expression": Boolean expected
postgres@#

postgres=# \if ':DBNAME' == 'postgres'
unrecognized value ":DBNAME == postgres" for "\if expression": Boolean expected
postgres@#


--
Angular momentum makes the world go 'round.





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux