加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

使用RPostgreSQL写入特定模式

发布时间:2020-12-13 16:28:05 所属栏目:百科 来源:网络整理
导读:我使用 RPostgreSQL读写数据.从任何模式中读取都可以完美地工作,但是我无法写入非公开模式.例如,以下代码将公用模式中的表放置在名称为myschema.tablex中 # write dataframe to postgres drv - dbDriver("PostgreSQL")con - dbConnect(drv,host="localhost",
我使用 RPostgreSQL读写数据.从任何模式中读取都可以完美地工作,但是我无法写入非公开模式.例如,以下代码将公用模式中的表放置在名称为myschema.tablex中
# write dataframe to postgres 
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv,host="localhost",user="postgres",password="zzzz",dbname="mydatabase",port="5436")
if(dbExistsTable(con,"myschema.tablex")) {
  dbRemoveTable(con,"myschema.vkt_tablex")}
dbWriteTable(con,"myschema.tablex",dataframe,row.names=F)

我想做的是将表tablex放在mysql中.我还尝试在连接中命名模式:dbname =“mydatabase.myschema”,并尝试在之前的错误中提到的参数schemaname.

这些方法都没有工作,所以我想知道是否有另一种可以使用的方法.

创建对象的默认模式由 search_path定义.一种方法是相应地进行设置.例如:
SET search_path = myschema,public;

我引用manual:

When objects are created without specifying a particular target
schema,they will be placed in the first schema listed in the search
path. An error is reported if the search path is empty.

您也可以将其设为default for a role,因此此角色会为每个连接自动设置.更多:

> How does the search_path influence identifier resolution and the “current schema”

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读