R数据库提取限制问题

时间:2015-02-09 15:37:04

标签: sql r rmysql

我是R的初学者,我不知道我的标题是否适合该问题,我在从R中的sql中提取一些数据时遇到问题,这是代码

> 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以外的数字结束那么没有错误为什么?< / p>

也是选择功能

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

提前致谢

1 个答案:

答案 0 :(得分: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"