Error in rsqlite_send_query

懵懂的女人 提交于 2019-12-13 00:39:45

问题


I have the below table names lco_act_data

head(lco_act_data)

X   SMZ_N     ACRES HH2030 ENR2030 RE2030 OFF2030 OTH2030 TOT2030
1       1 1603.5114  11325    1706    407    1368    1162    3085
2       2  907.2274   2079    1062    332    1028    1190    2654
3       3  758.8701   1407    1447     60    1949    1315    3829
4       4  170.1726    868       0     76     737     128     964
5       5  820.4855   5338     304    198    1343    1597    3249
6       6 1596.5201   4584    3272    346    1351    1411    3195

When I'm trying to alter the table using sqldf function below its throwing me the below error and I can't seem to understand why.

lco_act_data_edited <- sqldf("ALTER TABLE lco_act_data 
ADD Jurisdiction varchar(20),
State varchar(20),
Region varchar(20),
Subregion varchar(20)")

Error in rsqlite_send_query(conn@ptr, statement) : near ",": syntax error


回答1:


By default, the sqldf function runs without side-effects to it won't change existing objects. If you want to alter a table, you'll need to return it in the same command. You can pass in a vector of SQL statements. For example

lco_act_data_edited  <- sqldf(c(
    "ALTER TABLE lco_act_data ADD Jurisdiction varchar(20)", 
    "ALTER TABLE lco_act_data ADD State varchar(20)", 
    "select * from lco_act_data"
))

Related to sqldf FAQ #8



来源:https://stackoverflow.com/questions/43196180/error-in-rsqlite-send-query

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