为什么在 psql 中使用 \dt(+) 时看不到我的表 (PostgreSQL)?

dw8*_*547 16 schema postgresql psql table

我已经按照以下方式donor在架构中创建了表reference

CREATE TABLE reference.donor (
    donor_code smallint PRIMARY KEY,
    donor_name character varying NOT NULL,
    donor_type smallint REFERENCES reference.donor_type (type_id),
    alpha_2_code char(2) REFERENCES reference.iso_3166_1 (alpha_2_code)
);
Run Code Online (Sandbox Code Playgroud)

我已经按照以下方式填充了表格:

INSERT INTO reference.donor (donor_code, donor_name, donor_type, alpha_2_code)
SELECT donor_code, donor_name, donor_type, alpha_2_code
FROM reference.donor_template;
Run Code Online (Sandbox Code Playgroud)

当我运行时:

\dt+ reference.*
Run Code Online (Sandbox Code Playgroud)

在 psql 我看到reference.donor表:

                          List of relations
  Schema   |      Name      | Type  |  Owner   | Size  | Description 
-----------+----------------+-------+----------+-------+-------------
 reference | donor          | table | postgres | 16 kB | 
 reference | donor_template | table | postgres | 16 kB | 
 reference | donor_type     | table | postgres | 16 kB | 
 reference | iso_3166_1     | table | postgres | 48 kB | 
(4 rows)
Run Code Online (Sandbox Code Playgroud)

但是当我运行\dt+ donor*(或\dt(+))时,我没有看到reference.donor表格:

                          List of relations
  Schema   |      Name      | Type  |  Owner   | Size  | Description 
-----------+----------------+-------+----------+-------+-------------
 oecd_cl   | donor          | table | postgres | 16 kB | 
 reference | donor_template | table | postgres | 16 kB | 
 reference | donor_type     | table | postgres | 16 kB | 
(3 rows)
Run Code Online (Sandbox Code Playgroud)

为什么我只能在reference.donor运行\dt+ reference.*或运行时才能看到表格\dt+ *.donor
我期待\dt(或\dt+)显示它,但它没有。

search_path包括架构reference&用户postgres对架构reference和架构中的所有表具有所有权限,如下所示:

GRANT ALL ON ALL TABLES IN SCHEMA reference TO postgres;
Run Code Online (Sandbox Code Playgroud)

只是为了澄清,我有两个donor表,但它们在两个不同的模式中,即oecd.donor& reference.donor。(oecd.donor当我\dt(+)在 psql 中使用时,我可以看到没有任何问题)。

Erw*_*ter 14

psql 上的文档解释了:

只要pattern参数完全省略,\d命令就会显示当前模式搜索路径中可见的所有对象——这相当于*用作模式。(如果一个对象的包含模式在搜索路径中并且没有相同种类和名称的对象出现在搜索路径的前面,则称该对象是可见的。这相当于声明可以在没有显式模式的情况下通过名称引用该对象资格。)无论可见性如何,要查看数据库中的所有对象,请使用*.*作为模式。

大胆强调我的。
显然,您oecd_cl之前reference在您的搜索路径中。将此用于您的目的:

\dt *.donor*
Run Code Online (Sandbox Code Playgroud)

你会得到:

                          List of relations
  Schema   |      Name      | Type  |  Owner   | Size  | Description 
-----------+----------------+-------+----------+-------+-------------
 oecd_cl   | donor          | table | postgres | 16 kB | 
 reference | donor          | table | postgres | 16 kB | 
 reference | donor_template | table | postgres | 16 kB | 
 reference | donor_type     | table | postgres | 16 kB | 
(4 rows)
Run Code Online (Sandbox Code Playgroud)