如何使用R列出表,而不列出Postgres数据库中的视图?

问题描述 投票:1回答:1

?DBI::dbListTables中,我们可以阅读:

这应该包括视图和临时对象

的确如此。

但是,如何只查看表,但不包括视图?

如果有问题,我正在使用驱动程序RPostgres::Postgres()

r postgresql dbi
1个回答
0
投票

我建议表的系统目录视图为pg_tables

pg_tables

dbGetQuery(con, "SELECT * FROM pg_tables")

视图The manual:提供对数据库中每个表的有用信息的访问。

不包含视图,实例化视图或临时表,仅包含常规表(包括pg_tables表)。参见:

您可能要排除系统表,而仅检索模式和表名:

UNLOGGED

我为目录表添加了显式架构限定:How to check if a table exists in a given schema。通常不是必需的,但是可以防止混乱的dbGetQuery(con, "SELECT schemaname, tablename FROM pg_catalog.pg_tables WHERE schemaname !~ '^pg_' AND schemaname <> 'information_schema'") 设置。参见:

  • pg_catalog.pg_tables

search_path查看-如果需要的话:

How does the search_path influence identifier resolution and the "current schema"

视图pg_views提供对数据库中每个视图的有用信息的访问。

© www.soinside.com 2019 - 2024. All rights reserved.