新建的schema创建表以后,执行 select * from table_xxx; 查询时报错 ERROR:  relation "table_xxx" does not exist

testdb01=> select * from table_xxx;
ERROR:  relation "table_xxx" does not exist
LINE 1: select * from table_xxx;
                      ^
testdb01=> 

通过指定schema.table方式可以查询到:

testdb01=> select * from public.table_xxx;
 id |                                                                                                                                                                      
                                                                                                   geom                                                                    
                                                                                                                                                                           
                          | info 
----+----------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------+------
  1 | 0106000060E6100000010000000103000040010000000A0000005CA3069F2FFD32C01617D009928A314000000000000000005CA3069F2FFD32C01617D009928A31400000000000000000F26B4654041734C0D
45267B6B8402E40000000000000000087509FE8767C33C00F31DA54768A27400000000000000000ED227148639827C03CED065869052B400000000000000000970F062DBC2C26C0D661FB6F64DC3140000000000000
0000C7057482A4EA2DC077A0CC5DDD6733400000000000000000085869C54CBA2FC0AA89B58DD31530400000000000000000085869C54CBA2FC0AA89B58DD315304000000000000000005CA3069F2FFD32C01617D00
9928A31400000000000000000 | aaa
  2 | 0106000060E610000001000000010300004001000000060000002E4AB9F2C12028C07A4C81C0032528400000000000000000DCC6E95AA3862DC062DF5685DE6B234000000000000000001696C83FB5D423C06
6E1651998571A4000000000000000009C74F417FBB611C0A3EA85509FA8254000000000000000009C74F417FBB611C0A3EA85509FA8254000000000000000002E4AB9F2C12028C07A4C81C003252840000000000000
0000                                                                                                                                                                       
                          | bbb
(2 rows)

testdb01=> 

找到相关排查点:
Looks like it isn't a case folding issue. Check search_path (SHOW search_path or SELECT current_setting('search_path')) and compare it to the schema the table is in (\dt+ tablename) to make sure the table is on the client's path.
1,先确认是否表名大小写的问题,很显然,我的不是
2,检查 search_path ( SHOW search_path; )

testdb01=> SHOW search_path;
      search_path       
------------------------
 "$user", public, tiger
(1 row)

testdb01=> \dn;
    List of schemas
    Name     |  Owner   
-------------+----------
 public      | postgres
 public | test
 tiger       | postgres
 tiger_data  | postgres
 topology    | postgres
(5 rows)

testdb01=> \dt+ public.table_xxx;
                            List of relations
   Schema    |         Name         | Type  | Owner | Size  | Description 
-------------+----------------------+-------+-------+-------+-------------
 public | table_xxx | table | test  | 16 kB | 
(1 row)


我新建模式 public 时没有设置 search_path,使用SQL命令时也没有指定 schema,因此报错表不存在。


如果要设置 search_path 方然如下:

根据数据库设置 search_path 
ALTER database "db_xxx" SET search_path TO "schema_xxx";

根据用户设置 search_path 
ALTER user "user_xxx" SET search_path TO "schema_xxx";

我默认使用 public,public 仅临时测试使用,因此,我这里先不改了,命令使用时直接加上 schema.table 的方式规避该问题

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐