红移与 R

Redshift with R

我是通过 R 连接到 Redshift 的新手,我已经阅读了其他问题,但是当我尝试创建 table 时仍然遇到错误。 我已成功建立连接,我认为 table 已成功建立:

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)> 

但是,当我尝试检查 table 是否存在以及字段是否存在时,我收到以下消息:

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  

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

> 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 不是此 user/role 的默认架构。您可以尝试将模式设置为默认模式。看一眼 here

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

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

或破解为

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