2015-02-09 118 views
1

我是一个初学者到R和我不知道我的标题是否合适的问题,我有一个问题,从R中的SQL提取一些数据,这是代码R数据库提取限制问题

> flights = select(paste("SELECT DISTINCT flight FROM messages ORDER BY id DESC LIMIT", 1000)) 

> flights = select(paste("SELECT DISTINCT flight FROM messages ORDER BY id DESC LIMIT", 10000)) 

> flights = select(paste("SELECT DISTINCT flight FROM messages ORDER BY id DESC LIMIT", 100000)) 
Error in .local(conn, statement, ...) : 
could not run statement: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1e+05' at line 1 
Called from: eval(substitute(browser(skipCalls = pos), list(pos = 9 - frame)), 
envir = sys.frame(frame)) 

> flights = select(paste("SELECT DISTINCT flight FROM messages ORDER BY id DESC LIMIT", 1000000)) 
Error in .local(conn, statement, ...) : 
could not run statement: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1e+06' at line 1 
Called from: eval(substitute(browser(skipCalls = pos), list(pos = 9 - frame)), 
envir = sys.frame(frame)) 

> flights = select(paste("SELECT DISTINCT flight FROM messages ORDER BY id DESC LIMIT", 1000001)) 

> flights = select(paste("SELECT DISTINCT flight FROM messages ORDER BY id DESC LIMIT", 100000001)) 

所以这里是我的疑问,当限制小于10000或最多4个零没有错误,但约5或更多的零抛出错误。但如果限制以0以外的数字结束,那么没有错误,为什么?

而且选择功能提前

select <- function (query, connection=con) { 
return(as.data.frame(dbGetQuery(connection, query))) 
} 

感谢

回答

1

的大数字转换为科学记数法,您可以运行options(scipen=999),以防止这种情况:

options(scipen=999) 
paste("SELECT DISTINCT flight FROM messages ORDER BY id DESC LIMIT", 1000000) 
# "SELECT DISTINCT flight FROM messages ORDER BY id DESC LIMIT 1000000" 

要恢复它,运行options(scipen=0)

options(scipen=0) 
paste("SELECT DISTINCT flight FROM messages ORDER BY id DESC LIMIT", 1000000) 
#"SELECT DISTINCT flight FROM messages ORDER BY id DESC LIMIT 1e+06"