简体   繁体   中英

R Redshift dbExistTable dbWriteTable

I am having issues working with the schemas in Redshift connecting using R.

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

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

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

You may assign dbSendQuery() result to var if underlying sql returns a resultset. Here drop query doesn't return any result set Object. Try without assigning to any var.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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