r - 在 R 中的 MonetDBLite 中使用 WHERE 子句的问题
问题描述
我正在尝试在 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'.
有任何想法吗?
解决方案
对于常量值,您需要对数值使用单引号 ( '
) 或无。所以在你的例子中,
dbGetQuery(DB,'select * from table1 where "var1" = 1')
或者
dbGetQuery(DB,'select * from table1 where "var1" = \'1\'')
或者
dbGetQuery(DB,"select * from table1 where \"var1\" = '1'")
应该都可以。
一般规则是,标识符 ( table1
or var1
) 通常只在"
包含空格或大写字符时才需要用引号括起来,而常量 ( ) 只有在它们是字符串1
时才需要用引号括起来。'
推荐阅读
- sql - tsvector 的串联导致 Postgres 9.4.6 中的语法错误
- r - 嵌套for循环到应用?
- c - BitBlt 绘制黑色方块 (Windows 7)
- node.js - Angular2,找不到模块“应用程序/模型/用户”错误
- botframework - 我们无法访问您的机器人。确保您已将“teamsappstudio@microsoft.com”添加为管理员,然后重试
- kibana - 将 Elastic Search 数字字段转换为文本值
- mysql - 努力弄清楚如何设置这些约束
- vis.js - 有没有办法在节点之间建立 2 个直边?
- matlab - 在matlab中冻结轴大小
- calendar - 用于测试目的的 CloudKit 解决方法