【问题标题】:Problem using WHERE clause in MonetDBLite in R在 R 中的 MonetDBLite 中使用 WHERE 子句的问题
【发布时间】:2018-12-04 06:41:18
【问题描述】:

我正在尝试在 R64bit 3.5.1 中使用 MonetDBLite。 我的问题是我不能像这个例子一样使用 SQL 命令过滤数据:

dbGetQuery(DB,'select * from table1 where "var1" = "1"')

我收到此错误:

Error in .local(conn, statement, ...) : 
  Unable to execute statement 'select * from table1  where "var1" = "1"'.
Server says 'ParseException:SQLparser:42000!SELECT: identifier '1' unknown'.

有什么想法吗?

【问题讨论】:

    标签: r monetdblite


    【解决方案1】:

    对于常量值,您需要对数值使用单引号 (') 或不使用。所以在你的例子中,

    dbGetQuery(DB,'select * from table1 where "var1" = 1')

    dbGetQuery(DB,'select * from table1 where "var1" = \'1\'')

    dbGetQuery(DB,"select * from table1 where \"var1\" = '1'")

    应该都可以。

    一般规则是标识符(table1var1)一般只需要用"引用,如果它们包含空格或大写字符和常量(1)只需要用@987654329引用@ 如果它们是字符串。

    【讨论】:

    • 感谢您的回复。 \' 工作。在 where 子句中使用搜索参数怎么样:dbGetQuery(DB, 'SELECT * FROM table1 WHERE "var1" = \':x\'' , param = list(x = c('1','2','3')))。这不会返回任何东西。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多