简体   繁体   English

R Redshift dbExistTable dbWriteTable

[英]R Redshift dbExistTable dbWriteTable

I am having issues working with the schemas in Redshift connecting using R. 我在使用R进行Redshift连接中使用架构时遇到问题。

url <- "jdbc:url:port/database?user=X123&password=fakepassword"
conn <- dbConnect(driver, url)

so I connect fine, and when I list tables I notice the default schema is public, but I don't want to work with that schema, how do I switch schemas ? 因此,我的连接很好,当我列出表时,我注意到默认架构是公共的,但是我不想使用该架构,如何切换架构?

say if it is: lab_space 说是否:lab_space

when I try this, it still lists tables in public: 当我尝试这样做时,它仍然在公共列表中列出:

dbListTables(conn, schema='lab_space')

tried this and I get an error: 尝试了这个,我得到一个错误:

SET search_path = lab_space;

> SET search_path = 'cust_usr';
Error: unexpected symbol in "SET search_path"

I must be doing something wrong ? 我一定做错了什么 ?

When I try to say check for a table and delete: 当我尝试说检查表格并删除时:

droptable <- dbSendQuery(conn, "drop table if exists lab_space.Tablebla")

it will drop it, but still give me an error: 它将删除它,但仍然给我一个错误:

Error in .verify.JDBC.result(r, "Unable to retrieve JDBC result set for ",  : 
  Unable to retrieve JDBC result set for drop table if exists lab_space.Tablebla ([JDBC Driver]com.amazon.dsi.dataengine.impl.DSISimpleRowCountResult cannot be cast to com.amazon.dsi.dataengine.interfaces.IResultSet)

您可以使用dbSendUpdate更改架构,以更改连接的search_path

dbSendUpdate(jdbc_con,"set search_path to my_schema")

ok, on this one I went with this driver 好的,在这个驱动程序上,我和这个驱动程序一起使用

drv <- dbDriver("PostgreSQL") 

and then things worked with no stupid warnings errors, I guess R and Redshift still has a lot of growing up to do, not sure :- ) 然后一切正常,没有愚蠢的警告错误,我想R和Redshift仍有很多工作要做,不确定:-)

In redshift, you can set the search path with set search_path to <schema_name> (no equals) dbSendQuery(con,"set search_path to <schema_name>"); 在redshift中,您可以将set search_path to <schema_name> (不等于)来设置搜索路径dbSendQuery(con,"set search_path to <schema_name>");

You may assign dbSendQuery() result to var if underlying sql returns a resultset. 如果基础sql返回结果集,则可以将dbSendQuery()结果分配给var。 Here drop query doesn't return any result set Object. 此处drop查询不返回任何结果集Object。 Try without assigning to any var. 尝试不分配任何变量。

 dbSendQuery(conn, "drop table if exists lab_space.Tablebla")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM