Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 954AFB5DBD1 for ; Tue, 14 Jun 2011 16:14:03 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 38350-02-2 for ; Tue, 14 Jun 2011 19:13:56 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from sam.nabble.com (sam.nabble.com [216.139.236.26]) by mail.postgresql.org (Postfix) with ESMTP id 8AE64B5DBD6 for ; Tue, 14 Jun 2011 16:13:56 -0300 (ADT) Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1QWZ3k-0003fP-2l for pgsql-admin@postgresql.org; Tue, 14 Jun 2011 12:13:56 -0700 Date: Tue, 14 Jun 2011 12:13:56 -0700 (PDT) From: sundaram To: pgsql-admin@postgresql.org Message-ID: <1308078836071-4488964.post@n5.nabble.com> In-Reply-To: References: <48048E3E.2090807@megafon.hr> Subject: Re: psql shell return codes - checking if database exists MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.766 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RFC_ABUSE_POST=0.001, T_TO_NO_BRKTS_FREEMAIL=0.01, URI_HEX=1.122 X-Spam-Level: X-Archive-Number: 201106/79 X-Sequence-Number: 37705 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-tp2088362p4488964.html Sent from the PostgreSQL - admin mailing list archive at Nabble.com.