You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by yves pielusenet <yv...@free.fr> on 2006/09/14 22:55:37 UTC

DROP IF NOT EXISTS

I wonder if there is something similare like :
'drop index id_index if not exists' ?
I want to put a condition on a drop statement but it fails.
how can I do ?

thanks ,

-- 
yves piel


Re: DROP IF NOT EXISTS

Posted by Rajesh Kartha <ka...@gmail.com>.
yves pielusenet wrote:

>I wonder if there is something similare like :
>'drop index id_index if not exists' ?
>I want to put a condition on a drop statement but it fails.
>how can I do ?
>
>thanks ,
>
>  
>
Did you mean 'DROP INDEX <name> IF EXISTS ?

In any case, currently Derby does not support IF EXISTS in the DROP 
statement.

Not sure if this helps:
But, if you are using  JDBC, you could execute the 'DROP INDEX <name>' , 
catch the
SQLException to check for  the SQLState of  42X65 and print a useful 
message instead stating
index does not exist. If the index exists the drop should go through 
successfully.

-Rajesh

Re: DROP IF NOT EXISTS

Posted by yves pielusenet <yv...@free.fr>.
Thank you :)
Le vendredi 15 septembre 2006 à 01:55 +0200, Bernt M. Johnsen a écrit :
> yves pielusenet wrote:
> > I wonder if there is something similare like :
> > 'drop index id_index if not exists' ?
> > I want to put a condition on a drop statement but it fails.
> > how can I do ?
> > 
> 
> You could do it like this:
> 
> try {
>    stmt.executeUpdate("drop index id_index");
> } catch (SQLException e) {
>     if (!e.getSQLState().equals("xxxxx") {
>         throw e;
>     }
> }
> 
> 
> where xxxxx is the SQL State you get when trying to delete a
> non-existing index.
> 
> > thanks ,
> > 
> 
> 


Re: DROP IF NOT EXISTS

Posted by "Bernt M. Johnsen" <Be...@Sun.COM>.
yves pielusenet wrote:
> I wonder if there is something similare like :
> 'drop index id_index if not exists' ?
> I want to put a condition on a drop statement but it fails.
> how can I do ?
> 

You could do it like this:

try {
   stmt.executeUpdate("drop index id_index");
} catch (SQLException e) {
    if (!e.getSQLState().equals("xxxxx") {
        throw e;
    }
}


where xxxxx is the SQL State you get when trying to delete a
non-existing index.

> thanks ,
> 


-- 
Bernt Marius Johnsen, Database Technology Group,
Staff Engineer, Technical Lead Derby/Java DB
Sun Microsystems, Trondheim, Norway