当数据库名称全部为大写时,使用 rPostgreSQL 将表写入 Postgresql

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7475422/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-20 23:18:43  来源:igfitidea点击:

writing tables to Postgresql using rPostgreSQL when the database name is all capital letters

rpostgresql

提问by JD Long

I have a database in PostgreSQL which is named DATAin all caps. When I try to write an R data.frame to this database using RPostgreSQL like so:

我在 PostgreSQL 中有一个数据库,它以DATA全部大写字母命名。当我尝试使用 RPostgreSQL 将 R data.frame 写入此数据库时,如下所示:

library(RPostgreSQL)
con <- dbConnect(PostgreSQL(), host="myhost", 
                 user= "postgres", password="myPass", dbname="DATA")
dbWriteTable(con, "test", myDf)

I get the following error:

我收到以下错误:

Error in postgresqlExecStatement(conn, statement, ...) : 
  RS-DBI driver: (could not Retrieve the result : ERROR:  no schema has been selected to create in
)
[1] FALSE

However I notice that if I go to Postgresql and change the database name to data(lower case) and then change the script to call dbname="data"then it works like a charm.

但是我注意到,如果我转到 Postgresql 并将数据库名称更改为data(小写),然后将脚本更改为调用,dbname="data"那么它就像一个魅力。

I looked through the documentation for rPostgreSQL and the only mention of case I saw had to do with field names being case sensitive.

我查看了 rPostgreSQL 的文档,我看到的唯一提到的大小写与字段名称区分大小写有关。

So my questions are:

所以我的问题是:

  1. Is this behavior is expected?
  2. In my situation I control the DB so I can rename the database at will. How would I work around this behavior if I could not rename the database to all lower case?
  1. 这种行为是预期的吗?
  2. 在我的情况下,我控制数据库,因此我可以随意重命名数据库。如果无法将数据库重命名为全小写,我将如何解决此问题?

采纳答案by Dirk Eddelbuettel

There were definitely issues with tablesin upper-case. In think we handle that now: Try quoting it as "DATA" and it should go through. Unquoted table identifier all get lower-cased.

大写表格肯定存在问题。认为我们现在处理这个问题:尝试将其引用为“DATA”,它应该会通过。未加引号的表标识符全部变为小写。

Your issue is having the entire database in uppercase. It may also work with quoting, maybe even with '\"DATA\"'as an argument to dbConnect.

您的问题是将整个数据库设为大写。它也可以用于引用,甚至可以'\"DATA\"'作为 dbConnect 的参数。

Otherwise, reproducible examples on the list are best, and with some luck, Tomoaki will find a fix for your problem.

否则,列表中可重现的示例是最好的,如果运气好,Tomoaki 会找到解决您问题的方法。

Oh, and we spell it like the package: RPostgreSQL with capital arrrrrrr, especially today on talk like a piRate day.

哦,我们把它拼写成这样的包:RPostgreSQL 大写 arrrrrrr,尤其是今天的谈话就像一个海盗日。

Edit:Looks like there is simply no issue with current versions on Ubuntu 11.04:

编辑:看起来 Ubuntu 11.04 上的当前版本根本没有问题:

First, create DATA

首先,创建 DATA

edd@max:~$ createdb DATA
edd@max:~$ psql DATA
psql (8.4.8)
Type "help" for help.

DATA=# \q
edd@max:~$ 

Second, and in R, connect and save some data:

其次,在 R 中,连接并保存一些数据:

R> library(RPostgreSQL)
R> con <- dbConnect(PostgreSQL(), host="localhost", user= "edd", 
+                   password=".....", dbname="DATA")
R> con
<PostgreSQLConnection:(21936,0)> 
R> dbWriteTable(con, "quicktest", cars)
[1] TRUE
R> 

Third, check for content in DATA:

第三,检查内容DATA

DATA=# select * from quicktest limit 5;
 row_names | speed | dist 
-----------+-------+------
 1         |     4 |    2
 2         |     4 |   10
 3         |     7 |    4
 4         |     7 |   22
 5         |     8 |   16
(5 rows)

DATA=# 

Looking good to me.

对我来说很好看。