简体   繁体   English

Rstudio-server 中 sql 查询的空结果

[英]Empty result for sql query in Rstudio-server

I'm trying to get data from MySQL DB into Rstudio-server.我正在尝试将数据从 MySQL DB 获取到 Rstudio-server。 My actions are like我的行为就像

mydb = dbConnect(MySQL(), user='user', password='password', dbname='dbname', host='localhost')
query <- stri_paste('select sellings.updated_at AS Up_Date, concat(item_parameters.title, " ", ad_attributes.int_value) AS Class, CONCAT(geos.name, " ", geos.kind) AS place, geos.lon, geos.lat, sellings.price AS price, ((geo_routes.distance*2/1000 + 100)) AS delivery_cost FROM sellings, users, item_parameters, ad_attributes, geos, geo_routes WHERE users.encrypted_password!="" && item_parameters.title="Класс" && sellings.price IS NOT NULL && ad_attributes.int_value IS NOT NULL AND users.id=sellings.user_id AND item_parameters.id=ad_attributes.item_parameter_id AND sellings.id = ad_attributes.ad_id AND sellings.geo_guid = geos.guid AND geos.routable_guid = geo_routes.src_guid AND geo_routes.distance = (SELECT geo_routes.distance FROM geo_routes, geos WHERE geos.guid = sellings.geo_guid AND geo_routes.src_guid = geos.routable_guid AND geo_routes.dst_guid = (SELECT geos.routable_guid FROM geos WHERE geos.name = "Воронеж" && geos.kind = "г")) ORDER BY Up_Date;')
rs = dbGetQuery(mydb, query)

And I get an empty dataframe.我得到一个空的数据框。 But when I do the same with my local DB everything is OK.但是当我对本地数据库做同样的事情时,一切正常。 The query takes a pretty long time, about 3 minutes, but it works properly.查询需要很长时间,大约 3 分钟,但它可以正常工作。 Moreover the same query works right from the command line in MySQL.此外,相同的查询可以直接从 MySQL 的命令行运行。 On the server, it takes about 4 seconds.在服务器上,大约需要 4 秒。 OS of server is Debian 7, OS of local machine is Win 8. Any idea?服务器的操作系统是Debian 7,本地机器的操作系统是Win 8。知道吗?

Sometimes when querying from the command line the default schema has been set in a previous command. 有时从命令行查询时,默认模式已在上一个命令中设置。 This command doesn't carry over to R so the exact same query from a command line to a R session might not work. 该命令不会传递给R,因此从命令行到R会话的完全相同的查询可能无法正常工作。 Maybe check the dbname. 也许检查dbname。

Insert the below statements in your SQL query在您的 SQL 查询中插入以下语句

SET NOCOUNT ON
SET ANSI_WARNINGS OFF

It worked for me它对我有用

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

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