sqlite3 insert into dynamic table

戏子无情 提交于 2020-01-25 07:19:07

问题


I am using sqlite3 (maybe sqlite4 in the future) and I need something like dynamic tables. I have many tables with the same format: values_2012_12_27, values_2012_12_28, ... (number of tables is dynamic) and I want to select dynamically the table that receives some data.
I am using _sqlite3_prepare with INSERT INTO ? VALUES(?,?,?). Ofcourse this fails to compile (syntax error near ?). There is a nice and simple way to do this in sqlite ?

Thanks


回答1:


Using SQL parameters is not possible for identifiers such as table or column names.

If you don't want to keep so many prepared statements around, just prepare them on the fly whenever you need one.


If your database were properly normalized, you would have a single big values table with an extra date column. This organization is usually to be preferred, unless you have measured both and found that the better performance (if it actually exists) outweighs the overhead of managing multiple tables.



来源:https://stackoverflow.com/questions/14058863/sqlite3-insert-into-dynamic-table

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!