pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tim Cross <theophilusx@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Script checking to see what database it's connected to
Date: Mon, 22 Feb 2021 12:01:49 +1100
Message-ID: <87a6rw7vby.fsf@gmail.com> (raw)
In-Reply-To: <5e45b234-9390-e394-dc31-4dc3f7dbffdc@gmail.com>
References: <0437e8e0-5686-9a10-b204-0b9df86e27ef@gmail.com>
	<747b62a4-128c-093e-e212-252c34cea42c@gmail.com>
	<e3b70f2b-3ab9-a855-6ed9-68d0868e6eac@gmail.com>
	<5e45b234-9390-e394-dc31-4dc3f7dbffdc@gmail.com>


Rob Sargent <robjsargent@gmail.com> 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
>>>
>>> /pcode/
>>
>> I thought of that, yet so earnestly want avoid Yet Another Tiny Script.
>>
> Isn't it a toss-up with putting the check in every sql script?
> Or make it /really/ fancy: use proper arg parsing; check for existence
> of the sql script;  add a usage function; split stdout/stderr...  No end
> of fun.

that would be my approach. A general purpose 'launcher' script that does
argument checking, logging and reporting. Stick it in your bin directory
and then call that instead of psql directly. Now all your SQL scripts
are just DDL/DML statements. Nice thing is you can do it in whatever
scripting language your most comfortable with - bash, perl, ruby,
python, whatever and it is available for whatever project your working
on.

--
Tim Cross





view thread (11+ messages)  latest in thread

Message-ID: <87a6rw7vby.fsf@gmail.com>
Permalink:  ../87a6rw7vby.fsf@gmail.com/
Also on:    postgresql.org/message-id/87a6rw7vby.fsf@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: theophilusx@gmail.com
  Subject: Re: Script checking to see what database it's connected to
  In-Reply-To: <87a6rw7vby.fsf@gmail.com>
  References: <0437e8e0-5686-9a10-b204-0b9df86e27ef@gmail.com> <747b62a4-128c-093e-e212-252c34cea42c@gmail.com> <e3b70f2b-3ab9-a855-6ed9-68d0868e6eac@gmail.com> <5e45b234-9390-e394-dc31-4dc3f7dbffdc@gmail.com> <87a6rw7vby.fsf@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox