代码之家  ›  专栏  ›  技术社区  ›  Marco De Virgilis

sqldf r错误创建表

  •  0
  • Marco De Virgilis  · 技术社区  · 8 年前

    我正在用SQL做一些实验 R 使用sqldf包。 我尝试测试一些命令来检查输出,特别是我尝试创建表。

    代码如下:

    sqldf("CREATE TABLE tbl1 AS
           SELECT cut
           FROM diamonds")
    

    非常简单的代码,但是我得到了这个错误

    sqldf("CREATE TABLE tbl1 AS
    + SELECT cut
    +       FROM diamonds")
    data frame with 0 columns and 0 rows
    Warning message:
    In result_fetch(res@ptr, n = n) :
    Don't need to call dbFetch() for statements, only for queries
    

    为什么说表创建为0列和0行? 有人能帮忙吗?

    1 回复  |  直到 8 年前
        1
  •  0
  •   G. Grothendieck    8 年前

    • diamonds
    • create tbl1

    sqldf

    sqldf("select * from diamonds")
    

    • select

    verbose=TRUE

    sqldf("select * from diamonds limit 3", verbose = TRUE)
    

    sqldf: library(RSQLite)
    sqldf: m <- dbDriver("SQLite")
    sqldf: connection <- dbConnect(m, dbname = ":memory:")
    sqldf: initExtension(connection)
    sqldf: dbWriteTable(connection, 'diamonds', diamonds, row.names = FALSE)
    sqldf: dbGetQuery(connection, 'select * from diamonds limit 3')
    sqldf: dbDisconnect(connection)
      carat     cut color clarity depth table price    x    y    z
    1  0.23   Ideal     E     SI2  61.5    55   326 3.95 3.98 2.43
    2  0.21 Premium     E     SI1  59.8    61   326 3.89 3.84 2.31
    3  0.23    Good     E     VS1  56.9    65   327 4.05 4.07 2.31
    

    help("sqldf") sqldf github home page