使用R,如何在SQL Server数据库上获取“dbo”参数?

时间:2020-12-09 04:36:22

I have a SQL Server database, in spanish, and I want to obtain the results from SELECT * table.name

我有一个西班牙语的SQL Server数据库,我想从SELECT * table.name获取结果

To do this, I connect R with the database using odbc library.

为此,我使用odbc库将R连接到数据库。

After that, I do this:

在那之后,我这样做:

dbSendQuery(con,"SELECT * FROM [database].[dbo].[table.name]")

This returns me an error: std::bad_alloc

这会给我一个错误:std :: bad_alloc

But if I do this:

但如果我这样做:

dbSendQuery(con,"SELECT Id FROM [database].[dbo].[table.name]")

then I obtain good results

然后我获得了很好的结果

I have seen that only when varchar type of column names are involved in the query, then the error is shown, so I think that schema could be the responsible of this issue.

我已经看到,只有当查询中涉及varchar类型的列名时,才会显示错误,因此我认为架构可能是此问题的原因。

What can I do to don't have this error? The schema is "dbo"

我该怎么办才能没有这个错误?架构是“dbo”

Thanks!

1 个解决方案

#1


1  

Not knowing what your client environment is, I had a similar issue with ODBC + R + Linux + Sybase. I was able to query numeric columns but not character columns, receiving the same std::bad_alloc error. Your Id field is likely a number, while SELECT * is pulling in other columns with character data types.

不知道你的客户端环境是什么,我在ODBC + R + Linux + Sybase方面遇到了类似的问题。我能够查询数字列而不是字符列,接收相同的std :: bad_alloc错误。您的Id字段可能是一个数字,而SELECT *正在拉入具有字符数据类型的其他列。

The solution for me was to make sure I was using an ODBC driver that supports an 8-bytes SQLLEN datatype. On Linux running the command odbcinst -j showed me that the SQLLEN Size was 8 for my installed unixODBC version 2.3.1 running on RHEL Server 7.5 64-bit.

对我来说,解决方案是确保我使用的是支持8字节SQLLEN数据类型的ODBC驱动程序。在Linux上运行命令odbcinst -j向我显示我在RHEL Server 7.5 64位上运行的已安装的unixODBC版本2.3.1的SQLLEN大小为8。

By default the Sybase driver was symlinked to the 4-bytes version. Following the instructions below I made sure I was linking to the 8-bytes version and my problems were solved. Oddly I never experienced these issues when issuing commands via isql. Perhaps your SQL Server driver might be impacted in the same way.

默认情况下,Sybase驱动程序符号链接为4字节版本。按照下面的说明,我确保我链接到8字节版本,我的问题解决了。奇怪的是,在通过isql发出命令时,我从未遇到过这些问题。也许您的SQL Server驱动程序可能会以同样的方式受到影响。

http://infocenter.sybase.com/help/topic/com.sybase.infocenter.dc20155.1600/doc/html/san1361915533650.html

Posted this also in one of the related GitHub issues: https://github.com/r-dbi/odbc/issues/174#issuecomment-403106647

也发布在相关的GitHub问题之一:https://github.com/r-dbi/odbc/issues/174#issuecomment-403106647

#1


1  

Not knowing what your client environment is, I had a similar issue with ODBC + R + Linux + Sybase. I was able to query numeric columns but not character columns, receiving the same std::bad_alloc error. Your Id field is likely a number, while SELECT * is pulling in other columns with character data types.

不知道你的客户端环境是什么,我在ODBC + R + Linux + Sybase方面遇到了类似的问题。我能够查询数字列而不是字符列,接收相同的std :: bad_alloc错误。您的Id字段可能是一个数字,而SELECT *正在拉入具有字符数据类型的其他列。

The solution for me was to make sure I was using an ODBC driver that supports an 8-bytes SQLLEN datatype. On Linux running the command odbcinst -j showed me that the SQLLEN Size was 8 for my installed unixODBC version 2.3.1 running on RHEL Server 7.5 64-bit.

对我来说,解决方案是确保我使用的是支持8字节SQLLEN数据类型的ODBC驱动程序。在Linux上运行命令odbcinst -j向我显示我在RHEL Server 7.5 64位上运行的已安装的unixODBC版本2.3.1的SQLLEN大小为8。

By default the Sybase driver was symlinked to the 4-bytes version. Following the instructions below I made sure I was linking to the 8-bytes version and my problems were solved. Oddly I never experienced these issues when issuing commands via isql. Perhaps your SQL Server driver might be impacted in the same way.

默认情况下,Sybase驱动程序符号链接为4字节版本。按照下面的说明,我确保我链接到8字节版本,我的问题解决了。奇怪的是,在通过isql发出命令时,我从未遇到过这些问题。也许您的SQL Server驱动程序可能会以同样的方式受到影响。

http://infocenter.sybase.com/help/topic/com.sybase.infocenter.dc20155.1600/doc/html/san1361915533650.html

Posted this also in one of the related GitHub issues: https://github.com/r-dbi/odbc/issues/174#issuecomment-403106647

也发布在相关的GitHub问题之一:https://github.com/r-dbi/odbc/issues/174#issuecomment-403106647