在R的MonetDBLite中使用WHERE子句的问题

时间:2018-12-04 06:41:18

标签: r monetdblite

我正在尝试在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'.

有什么想法吗?

1 个答案:

答案 0 :(得分: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引号。仅当它们是字符串时,才需要用'引起来。