简体   繁体   English

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

[英]Problem using WHERE clause in MonetDBLite in R

I am trying to use MonetDBLite in R64bit 3.5.1. 我正在尝试在R64bit 3.5.1中使用MonetDBLite。 My problem is that I can not filter the data using SQL command like this example: 我的问题是我无法使用SQL过滤此示例中的数据:

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

I get this error: 我收到此错误:

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

Any ideas? 有任何想法吗?

For constant values, you need to use single quotes ( ' ) or none for numeric values. 对于常量值,您需要使用单引号( ' )或不使用数字值。 So in your example, 所以在你的例子中

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

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

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

should all work. 应该一切正常。

The general rule is that identifiers ( table1 or var1 ) generally only need to be quoted with " if they contain spaces or uppercase characters and constants ( 1 ) only need to be quoted with ' if they are character strings. 一般规则是,如果标识符( table1var1 )包含空格或大写字符,则通常仅需用"引号"如果常量( 1 )是字符串,则仅需用'引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM