SQLite Forum

SELECT using variables
Login
In your first code sample, the problem is that [parameters in queries cannot be schema names][1]. SQLite needs all of the names up front to prepare the query for efficient execution. The query planner cannot know what to do with a statement if you don't provide the elements of the schema it will operate over, so if SQLite allowed this, it would have to re-prepare the query each time it ran.

As for your second code sample, I’m not clear on the problem. I'll need you to post more details; as it stands, I'm reduced to wild guesses. What is the content of `name`, what errors do you get, does the same query work in the `sqlite3` shell, etc.


[1]: https://www.sqlite.org/cintro.html#binding_parameters_and_reusing_prepared_statements