Re: IF EXISTS - Mailing list pgsql-general

From Jaime Casanova
Subject Re: IF EXISTS
Date
Msg-id c2d9e70e0511141351m6f526bbcw93e5895ad54ef8c@mail.gmail.com
Whole thread Raw
In response to IF EXISTS  ("P.M" <pmdanger@yahoo.com>)
Responses Re: IF EXISTS
List pgsql-general
On 11/14/05, P.M <pmdanger@yahoo.com> wrote:
> Hi,
>
> I would like to know if "IF EXISTS" exists under
> postgresql ?
> because i did not find it.
>
> before to create users or database, i would like to be
> sure that they do not exist already.
>
> so how can i test it and do something like :
>
> IF EXISTS database "test" DROP database "test";
>
> thanks a lot,
> Maileen
>
>

something in shell is fine?

---------SCRIPT BEGIN HERE ------------
#!/bin/sh

psql template1 -A -t -c "SELECT datname FROM pg_database WHERE
datname = 'test'" | while read D ; do
        dropdb test
# or you can do
# psql template1 -c "DROP DATABASE test"
# whatever you feel comfortable with
done

createdb test
---------SCRIPT END HERE ------------


--
regards,
Jaime Casanova
(DBA: DataBase Aniquilator ;)

pgsql-general by date:

Previous
From: Michelle Konzack
Date:
Subject: 3 x PostgreSQL in cluster/redunant
Next
From: Scott Marlowe
Date:
Subject: Re: 3 x PostgreSQL in cluster/redunant