Redshift with R



我是通过R连接到Redshift的新手,我读过其他问题,但在尝试创建表时仍然遇到错误。我已经成功地建立了一个连接,我认为成功地设置了表:

redshiftcon <- dbConnect(mm, user="username", password="secret_password",
                    dbname="dbtable", host="hostname", port="portnumber")

dbSendQuery(redshiftcon,
"create table ss_playground.test_table (unique_id VARCHAR,
category VARCHAR,
name VARCHAR,
number_min float);")
<PostgreSQLResult:(70214,5,1)> 

然而,当我试图检查表是否存在以及字段是否存在时,我会得到以下消息:

dbExistsTable(redshiftcon, ss_playground.test_table)
Error in is(object, Cl) : 
error in evaluating the argument 'name' in selecting a method for function
'dbExistsTable': Error: object 'ss_playground.test_table' not found
> dbExistsTable(redshiftcon, 'ss_playground.test_table')
[1] FALSE  

我很困惑,因为我以为表创建成功了,但在数据库中找不到它。当我尝试发送并再次创建它时,我会得到以下信息:

> dbSendQuery(redshiftcon,
         "create table ss_playground.test_table (unique_id VARCHAR,
category VARCHAR,
name VARCHAR,
number_min float);")
Error in postgresqlExecStatement(conn, statement, ...) : 
RS-DBI driver: (could not Retrieve the result : ERROR:  Relation   
'test_table' already exists)

我有什么东西不见了吗?

请帮忙!感谢

我认为ss_playground不是这个用户/角色的默认模式。您可以尝试将模式设置为默认模式。看看这里。

要快速修复您的代码,您可以尝试:

dbExistsTable(redshiftcon, c("ss_playground","test_table"))

或者将其破解为

any(grepl("test_table",dbListTables(redshiftcon)))

最新更新