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

2021-02-21 Thread Thomas Kellerer
Julien Rouhaud schrieb am 22.02.2021 um 02:19: >> The output: >> $ psql12 -f test_pg.sql >> t >> connected to postgres >> got here >> psql:test_pg.sql:15: ERROR: syntax error at or near "exit" >> LINE 1: exit > > Well, the supported commands did work. You should probably look at > https://www.pos

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

2021-02-21 Thread Ron
On 2/21/21 7:19 PM, Julien Rouhaud wrote: [snip] Well, the supported commands did work. You should probably look at https://www.postgresql.org/docs/current/app-psql.html, you'd see that "exit" is not a supported command and you should instead use \q[uit]. I recommend looking at the semantics of

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

2021-02-21 Thread Julien Rouhaud
On Mon, Feb 22, 2021 at 9:00 AM Ron wrote: > > On 2/21/21 5:26 PM, Julien Rouhaud wrote: > > On Mon, Feb 22, 2021 at 7:19 AM Ron 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 > \end

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

2021-02-21 Thread Tim Cross
Rob Sargent writes: >>> >>> Take it up a notch? Write a script which takes the dbname and the >>> script name: >>> >>> /pcode/ >>> >>> #!/bin/bash -e >>> if [[ $# -ne 2 ]]; then echo "missing arg(s)"; exit 2; fi >>> dbn=$1; shift; >>> sql=$1; shift; >>> psql --dbname $dbn --file $sql >>> >>> /

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

2021-02-21 Thread Ron
On 2/21/21 6:49 PM, Rob Sargent wrote: Take it up a notch?  Write a script which takes the dbname and the script name: /pcode/ #!/bin/bash -e if [[ $# -ne 2 ]]; then echo "missing arg(s)"; exit 2; fi dbn=$1; shift; sql=$1; shift; psql --dbname $dbn --file $sql /pcode/ I thought of that

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

2021-02-21 Thread Ron
On 2/21/21 5:26 PM, Julien Rouhaud wrote: On Mon, Feb 22, 2021 at 7:19 AM Ron 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

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

2021-02-21 Thread Rob Sargent
Take it up a notch?  Write a script which takes the dbname and the script name: /pcode/ #!/bin/bash -e if [[ $# -ne 2 ]]; then echo "missing arg(s)"; exit 2; fi dbn=$1; shift; sql=$1; shift; psql --dbname $dbn --file $sql /pcode/ I thought of that, yet so earnestly want avoid Yet Anoth

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

2021-02-21 Thread Ron
On 2/21/21 5:26 PM, Rob Sargent wrote: On 2/21/21 4:18 PM, Ron wrote: 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 forge

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

2021-02-21 Thread Rob Sargent
On 2/21/21 4:18 PM, Ron wrote: 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

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

2021-02-21 Thread Julien Rouhaud
On Mon, Feb 22, 2021 at 7:19 AM Ron 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.

Script checking to see what database it's connected to

2021-02-21 Thread Ron
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 b