7

Right now I have this statement

DELETE FROM sqlite_sequence where name = 'table_name';

which works fine in most cases, but now I have a case where the sqlite_sequence table is not being created and so I get back

no such table: sqlite_sequence

I need a statement that only does the delete if the table exists. I've found this statement to tell me if the table exists or not

SELECT name FROM sqlite_master WHERE type='table';

But so far I've been unable to successfully pair it with the delete satement

lightswitch05
  • 9,058
  • 7
  • 52
  • 75

1 Answers1

7

The table existence check should include the name, of course

SELECT count(*) FROM sqlite_master WHERE type='table' AND name='table_name';

But you'll have to do it from the calling application in separate statements, i.e. run the above, and based on the count (naturally 1=true, 0=false) as boolean value, you can proceed to run the DELETE statement.

RichardTheKiwi
  • 105,798
  • 26
  • 196
  • 262