1

我是通过 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)

有什么我想念的吗?

请帮忙!谢谢

4

1 回答 1

2

我认为这ss_playground不是此用户/角色的默认架构。您可以尝试将架构设置为默认值。看看这里

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

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

或将其破解为

any(grepl("test_table",dbListTables(redshiftcon)))
于 2016-01-13T15:00:09.837 回答