列出PostgreSQL模式中的表 [英] List tables in a PostgreSQL schema

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

问题描述

当我在psql中执行 \dt 时,我只会得到当前模式中的表列表( public

When I do a \dt in psql I only get a listing of tables in the current schema (public by default).

如何获取所有模式或特定模式中所有表的列表?

How can I get a list of all tables in all schemas or a particular schema?

推荐答案

在所有模式中:

=> \dt *.*

在特定模式中:

=> \dt public.*

可以使用带有某些限制的正则表达式

\dt (public|s).(s|t)
       List of relations
 Schema | Name | Type  | Owner 
--------+------+-------+-------
 public | s    | table | cpn
 public | t    | table | cpn
 s      | t    | table | cpn




高级用户可以使用正则表达式,例如字符类,例如[0-9]以匹配任何数字。除以外,所有正则表达式特殊字符均按第9.7.3节的规定工作。如上所述,将 * 转换为正则表达式。* 转换为 $ 字面匹配。您可以通过为编写来模拟这些模式字符。(R + |) 表示 R * ,或(R |)表示 R ?。不需要 $ 作为正则表达式字符,因为该模式必须与整个名称匹配,这与常规对正则表达式的解释不同(换句话说, $ 会自动添加到您的模式中)。如果您不希望锚定模式,请在开头和/或结尾处写 * 。请注意,在双引号中,所有正则表达式特殊字符都会失去其特殊含义,并且会在字面上匹配。另外,正则表达式特殊字符在运算符名称模式中即字面上匹配(即 \do 的参数)。

Advanced users can use regular-expression notations such as character classes, for example [0-9] to match any digit. All regular expression special characters work as specified in Section 9.7.3, except for . which is taken as a separator as mentioned above, * which is translated to the regular-expression notation .*, ? which is translated to ., and $ which is matched literally. You can emulate these pattern characters at need by writing ? for ., (R+|) for R*, or (R|) for R?. $ is not needed as a regular-expression character since the pattern must match the whole name, unlike the usual interpretation of regular expressions (in other words, $ is automatically appended to your pattern). Write * at the beginning and/or end if you don't wish the pattern to be anchored. Note that within double quotes, all regular expression special characters lose their special meanings and are matched literally. Also, the regular expression special characters are matched literally in operator name patterns (i.e., the argument of \do).

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

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