0

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

有任何想法吗?

4

1 回答 1

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'")

应该都可以。

一般规则是,标识符 ( table1or var1) 通常只在"包含空格或大写字符时才需要用引号括起来,而常量 ( ) 只有在它们是字符串1时才需要用引号括起来。'

于 2018-12-04T07:05:54.280 回答