Re: IF EXISTS

From: Samer Abukhait <abukhait(at)gmail(dot)com>
To: Jaime Casanova <systemguards(at)gmail(dot)com>
Cc: "P(dot)M" <pmdanger(at)yahoo(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: IF EXISTS
Date: 2005-11-14 22:42:06
Message-ID: 7d215b0c0511141442tf293c63i1895bc485b1ead01@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

How about if exists (select .. from ..)

On 11/14/05, Jaime Casanova <systemguards(at)gmail(dot)com> wrote:
> On 11/14/05, P.M <pmdanger(at)yahoo(dot)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 ;)
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
> choose an index scan if your joining column's datatypes do not
> match
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jim C. Nasby 2005-11-14 22:44:45 Re: Choosing PostgreSQL as the database for our next project
Previous Message Scott Marlowe 2005-11-14 21:57:27 Re: 3 x PostgreSQL in cluster/redunant