Nyx*_*nyx 300 postgresql postgresql-9.1 psql
当我\dt在psql中执行一个操作时,我只获得当前模式中的表列表(public默认情况下).
如何获取所有模式或特定模式中的所有表的列表?
Clo*_*eto 458
在所有模式中:
=> \dt *.*
Run Code Online (Sandbox Code Playgroud)
在特定架构中:
=> \dt public.*
Run Code Online (Sandbox Code Playgroud)
可以使用具有某些限制的正则表达式
\dt (public|s).(s|t)
List of relations
Schema | Name | Type | Owner
--------+------+-------+-------
public | s | table | cpn
public | t | table | cpn
s | t | table | cpn
Run Code Online (Sandbox Code Playgroud)
高级用户可以使用正则表达式表示法(例如字符类),例如[0-9]来匹配任何数字.所有正则表达式特殊字符都按照第9.7.3节的规定工作,除了.它被视为如上所述的分隔符,*被转换为正则表达式表示法.,?翻译为.,和字面匹配的$.你可以通过写作来模仿这些模式字符吗?对于R,(R + |),对于R,(R |).$不需要作为正则表达式字符,因为模式必须与整个名称匹配,这与正则表达式的通常解释不同(换句话说,$会自动附加到您的模式).如果您不希望锚定模式,请在开头和/或结尾写入*.请注意,在双引号内,所有正则表达式特殊字符都会失去其特殊含义并按字面匹配.此外,正则表达式特殊字符在运算符名称模式(即\ do的参数)中按字面匹配.
Jak*_*nia 234
您可以从中选择表格 information_schema
SELECT * FROM information_schema.tables
WHERE table_schema = 'public'
Run Code Online (Sandbox Code Playgroud)
Rad*_*icz 45
或者information_schema可以使用pg_tables:
select * from pg_tables where schemaname='public';
Run Code Online (Sandbox Code Playgroud)
lin*_*nog 11
如果您有兴趣列出特定架构中的所有表,我发现这个答案相关:
SELECT table_schema||'.'||table_name AS full_rel_name
FROM information_schema.tables
WHERE table_schema = 'yourschemaname';
Run Code Online (Sandbox Code Playgroud)
小智 7
对于未来遇到这种情况的人:
如果您想查看多个模式的关系列表:
$psql mydatabase
mydatabase=# SET search_path TO public, usa; #schema examples
SET
mydatabase=# \dt
List of relations
Schema | Name | Type | Owner
--------+-----------------+-------+----------
public | counties | table | postgres
public | spatial_ref_sys | table | postgres
public | states | table | postgres
public | us_cities | table | postgres
usa | census2010 | table | postgres
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
266735 次 |
| 最近记录: |