DROP TABLE [IF EXISTS]
DROP INDEX [IF EXISTS]
CREATE TABLE [IF NOT EXISTS]
and so on...

On 1/25/07, Nicolas Williams <[EMAIL PROTECTED]> wrote:
On Thu, Jan 25, 2007 at 10:35:23AM -0500, Anderson, James H (IT) wrote:
> I need a way to drop a table only if that table exists. How would I do
> that?

You'd think this would work:

SELECT CASE WHEN
    (SELECT count(*) FROM sqlite_master WHERE
        type = 'table' AND name = 'foo') > 0
    THEN (DROP TABLE foo) END;

but it doesn't (it yields a syntax error).

In fact, inserts and updates inside a select case when all yield syntax
errors.

W.r.t. to dropping a table inside a select case when, well, you should
know whether the schema to begin with, so that makes sense.

Nico
--

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------




--
Puneet Kishor http://punkish.eidesis.org/
Nelson Inst. for Env. Studies, UW-Madison http://www.nelson.wisc.edu/
Open Source Geospatial Foundation http://www.osgeo.org/education/
---------------------------------------------------------------------
collaborate, communicate, compete
=====================================================================

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to