From: sundaram <sundaram.bioreliance@gmail.com>
To: pgsql-admin@postgresql.org
Subject: Re: psql shell return codes - checking if database exists
Date: Tue, 14 Jun 2011 12:13:56 -0700 (PDT)
Message-ID: <1308078836071-4488964.post@n5.nabble.com> (raw)
In-Reply-To: <fu25vb$oii$1@ger.gmane.org>
References: <48048E3E.2090807@megafon.hr>
<fu25vb$oii$1@ger.gmane.org>
Perhaps the grep solution will only provide an accurate response if the
database name is not a substring of some other database name.
In other words, if one were to attempt to confirm that database prod10
exists- they might execute (per the suggestion):
psql --list | grep prod10
But, the result could be misleading if the following databases also exist on
the same server:
prod100
prod101
prod1000
myprod10
yourprod101
etc.
I would like to suggest querying directly from the system table pg_database
like this:
psql --tuples-only --command "select * from pg_database where datname =
'prod10';"
You can pipe and process the result as appropriate for your needs.
--
View this message in context: http://postgresql.1045698.n5.nabble.com/psql-shell-return-codes-checking-if-database-exists-tp208836...
Sent from the PostgreSQL - admin mailing list archive at Nabble.com.
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 using the --to and --cc options:
reply via email
To: pgsql-admin@postgresql.org
Cc: sundaram.bioreliance@gmail.com
Subject: Re: psql shell return codes - checking if database exists
In-Reply-To: <1308078836071-4488964.post@n5.nabble.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