使用 R 列出 Postgres 模式中的表 [英] List tables within a Postgres schema using R

查看:48
本文介绍了使用 R 列出 Postgres 模式中的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 R 和 RPostgreSQL 包连接到 PostgreSQL 数据库.数据库有许多架构,我想知道哪些表与特定架构相关联.

I'm connecting to a PostgreSQL db using R and the RPostgreSQL package. The db has a number of schemas and I would like to know which tables are associated with a specific schema.

到目前为止我已经尝试过:

So far I have tried:

dbListTables(db, schema="sch2014")
dbGetQuery(db, "dt sch2014.*")
dbGetQuery(db, "\dt sch2014.*")
dbGetQuery(db, "\\dt sch2014.*")

都没有奏效.

这个相关问题也存在:使用R,这将通过在连接处定义模式来解决问题.但是,还没有得到答复!

This related question also exists: Setting the schema name in postgres using R, which would solve the problem by defining the schema at the connection. However, it's not yet been answered!

推荐答案

阅读这个答案 https://stackoverflow.com/a/15644435/2773500 有帮助.我可以使用以下内容来获取与特定架构关联的表:

Reading this answer https://stackoverflow.com/a/15644435/2773500 helped. I can use the following to get the tables associated with a specific schema:

dbGetQuery(db,
           "SELECT table_name FROM information_schema.tables
                   WHERE table_schema='sch2014'")

这篇关于使用 R 列出 Postgres 模式中的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆