P-Gn
P-Gn

Reputation: 24611

Creating a table conditionally in SQlite

This is probably very basic stuff. I want to create a table if a certain condition is met. Basically I have a db with a version number, and if the version is as expected, a new table is created.

This is pretty straightforward to do, say, in python, but is there a pure SQL way, or then a pure SQLite way, of doing this? Basically I want to know if my update scripts could be free of any other programming langage other than SQL (or SQLite's SQL).

I looked at the CASE clause but it seems I can't use it as a top-level switch statement.

Upvotes: 2

Views: 397

Answers (1)

Larry Lustig
Larry Lustig

Reputation: 51000

No, there's no way to do this. SQLite has no flow control statements and the only if condition you can specify on the CREATE TABLE command is IF NOT EXISTS.

You will have to use a scripting language to execute this logic.

Upvotes: 2

Related Questions