Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id C22E52E00A6 for ; Tue, 15 Apr 2008 09:11:21 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 55109-01-3 for ; Tue, 15 Apr 2008 09:11:18 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by developer.postgresql.org (Postfix) with ESMTP id 55DEB2E007F for ; Tue, 15 Apr 2008 09:10:37 -0300 (ADT) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1Jljza-0001Y4-5o for pgsql-admin@postgresql.org; Tue, 15 Apr 2008 12:10:30 +0000 Received: from pirus.securax.be ([213.16.46.130]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 15 Apr 2008 12:10:30 +0000 Received: from milen by pirus.securax.be with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 15 Apr 2008 12:10:30 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-admin@postgresql.org From: "Milen A. Radev" Subject: Re: psql shell return codes - checking if database exists Date: Tue, 15 Apr 2008 15:10:18 +0300 Lines: 15 Message-ID: References: <48048E3E.2090807@megafon.hr> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: pirus.securax.be User-Agent: Thunderbird 2.0.0.12 (Windows/20080213) In-Reply-To: <48048E3E.2090807@megafon.hr> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200804/142 X-Sequence-Number: 28906 Mario Splivalo написа: > I need to check, from a bash script, if certain database exists in a > postgres cluster. When I issue: > > psql -U someuser somedatabase > > psql returns error code 2 regardless of 'no user' or 'no database' > condition. How could I distinguish from the two? A workaround: add "--list" option to the command line and grep for the database you need. -- Milen A. Radev